Skip to content

Commit

Permalink
better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanasati committed Jan 7, 2024
1 parent cd5cc08 commit 121d12b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 0 additions & 6 deletions internal/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ type Result struct {
// todo in all exports, include individual run details

var summaryNoColor = `
Benchmarking Summary
--------------------
Executed Command: {{ .Command }}
Total iterations: {{ .Iterations }}
Average time taken: {{ .Average }} ± {{ .StandardDeviation }}
Range: {{ .Min }} ... {{ .Max }}
`

var summaryColor = `
${blue}Benchmarking Summary ${reset}
${blue}-------------------- ${reset}
${yellow}Executed Command: ${green}{{ .Command }} ${reset}
${yellow}Total iterations: ${green}{{ .Iterations }} ${reset}
${yellow}Average time taken: ${green}{{ .Average }} ± {{ .StandardDeviation }} ${reset}
Expand Down
29 changes: 23 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/Shravan-1908/atomic/internal"
"github.com/Shravan-1908/commando"
"github.com/google/shlex"
"github.com/schollz/progressbar/v3"
"github.com/mitchellh/colorstring"
"github.com/schollz/progressbar/v3"
)

const (
Expand Down Expand Up @@ -158,7 +158,7 @@ func run(command []string, verbose bool, ignoreError bool) (time.Duration, error
return duration, nil
}

// todo automatically determine the number of runs
// todo automatically determine the number of runs -> run min 3s & min 10 runs
func benchmark(opts BenchmarkOptions) ([]int64, bool) {
// actual runs, each entry stored in microseconds
var runs []int64
Expand All @@ -184,18 +184,19 @@ func benchmark(opts BenchmarkOptions) ([]int64, bool) {
for i := 1; i <= opts.iterations; i++ {
internal.Log("purple", fmt.Sprintf("***********\nRunning "+word+" %d\n***********", i))

// dont ignore errors in prepare command execution, dont output it either
// dont output prepare command execution
if opts.executePrepareCmd {
_, e := run(opts.prepareCmd, false, false)
_, e := run(opts.prepareCmd, false, opts.ignoreError)
if errors.As(e, &processErr) {
internal.Log("red", processErr.Error())
// todo suggest using -I and -v flag
internal.Log("yellow", "You should consider using -I/--ignore-error flag to ignore failures in the command execution. Alternatively, you can also try the -v/--verbose flag to show the output of the command. If the command is actually a shell function, use -s/--shell flag to execute it via a shell.")
return nil, true
}
}
dur, e := run(opts.command, opts.verbose, opts.ignoreError)
if errors.As(e, &processErr) {
internal.Log("red", processErr.Error())
internal.Log("yellow", "You should consider using -I/--ignore-error flag to ignore failures in the command execution. Alternatively, you can also try the -v/--verbose flag to show the output of the command. If the command is actually a shell function, use -s/--shell flag to execute it via a shell.")
return nil, true
}
runs = append(runs, (dur.Microseconds()))
Expand Down Expand Up @@ -230,6 +231,7 @@ func benchmark(opts BenchmarkOptions) ([]int64, bool) {
_, e := run(opts.prepareCmd, false, false)
if errors.As(e, &processErr) {
internal.Log("red", processErr.Error())
internal.Log("yellow", "You should consider using -I/--ignore-error flag to ignore failures in the command execution. Alternatively, you can also try the -v/--verbose flag to show the output of the command. If the command is actually a shell function, use -s/--shell flag to execute it via a shell.")
return nil, true
}
}
Expand All @@ -238,6 +240,7 @@ func benchmark(opts BenchmarkOptions) ([]int64, bool) {
if errors.As(e, &processErr) {
bar.Clear()
internal.Log("red", processErr.Error())
internal.Log("yellow", "You should consider using -I/--ignore-error flag to ignore failures in the command execution. Alternatively, you can also try the -v/--verbose flag to show the output of the command. If the command is actually a shell function, use -s/--shell flag to execute it via a shell.")
return nil, true
}
runs = append(runs, (dur.Microseconds()))
Expand Down Expand Up @@ -363,7 +366,7 @@ func main() {

// * benchmark each command given
for index, commandString := range strings.Split(args["commands"].Value, commando.VariadicSeparator) {
if _, err := colorstring.Printf("[bold][magenta]Benchmark %d: [blue]%s", index + 1, commandString); err != nil {
if _, err := colorstring.Printf("[bold][magenta]Benchmark %d: [cyan]%s", index+1, commandString); err != nil {
panic(err)
}
// ! don't remove this println: for some weird reason the above colorstring.Printf
Expand Down Expand Up @@ -449,6 +452,20 @@ func main() {
// }
// todo export all results
// result.Export(exportFormats)

// for comparision
/*
let ratio = result.mean / fastest.mean;
let ratio_stddev = match (result.stddev, fastest.stddev) {
(Some(result_stddev), Some(fastest_stddev)) => Some(
ratio
* ((result_stddev / result.mean).powi(2)
+ (fastest_stddev / fastest.mean).powi(2))
.sqrt(),
),
_ => None,
};
*/
})

commando.Parse(nil)
Expand Down

0 comments on commit 121d12b

Please sign in to comment.