Skip to content

Commit

Permalink
✨ feat(benchvisual): update baseline
Browse files Browse the repository at this point in the history
consider cpu core num when compare ns/op
  • Loading branch information
kevineluo committed Apr 18, 2023
1 parent 1f9ed13 commit 11c57b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ In the visualization progress, we will visualize Benchmark in a concepts mapping
- scenarios -> dummy values in charts(group name)
benchvisual also provides json output format for your secondary development, use --json to let it output json file.
benchvisual also provides baseline feature, use --baseline to let it calculate baseline for each Benchmark.`,
Version: "0.2.0",
Version: "0.2.1",
RunE: func(cmd *cobra.Command, args []string) (err error) {
var regex *regexp2.Regexp
if *sep == "" {
Expand Down
3 changes: 2 additions & 1 deletion internal/bench/baseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func Baseline(sets []Set, baselines []float64) {
less bool
)
if baselines[0] > 0 {
fast = benchmark.NsPerOp < baselines[0]
// consider cpu core nums when compare
fast = benchmark.NsPerOp*float64(benchmark.CPUCores) < baselines[0]
}
if baselines[1] > 0 {
small = benchmark.Mem.BytesPerOp < baselines[1]
Expand Down
16 changes: 14 additions & 2 deletions internal/bench/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type Set struct {
// evaluate divisions so that results come out as floats instead of being truncated to
// integers.
type Benchmark struct {
Name string `json:"name,omitempty"`
Runs int `json:"runs,omitempty"` // benchmark times
Name string `json:"name,omitempty"`
CPUCores int `json:"cpu_cores,omitempty"`
Runs int `json:"runs,omitempty"` // benchmark times

// For a Benchmark function BenchXXX10000, its target is XXX, and its Scenario is 10000
// The Benchmark of different target is compared in each Scenario
Expand Down Expand Up @@ -161,6 +162,17 @@ func ParseBench(line string, sep string, regex *regexp2.Regexp) (bench *Benchmar
})
bench.Name, split = popLeft(split)

// parse cpu core nums
sepIdx := strings.LastIndex(bench.Name, "-")
if sepIdx == -1 {
return nil, fmt.Errorf("[ParseBench] invalid benchmark name, no '-' found")
}
bench.CPUCores, err = strconv.Atoi(bench.Name[sepIdx+1:])
if err != nil {
return nil, fmt.Errorf("[ParseBench] invalid benchmark name, failed to parse cpu core nums")
}
bench.Name = bench.Name[:sepIdx]

if regex != nil {
// with regexp
log.Debug("[ParseBench] in regex mode", "regexp", regex.String())
Expand Down

0 comments on commit 11c57b4

Please sign in to comment.