diff --git a/cmd/root.go b/cmd/root.go index ab40f2b..d5c261d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 == "" { diff --git a/internal/bench/baseline.go b/internal/bench/baseline.go index d171d97..3897f33 100644 --- a/internal/bench/baseline.go +++ b/internal/bench/baseline.go @@ -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] diff --git a/internal/bench/benchmark.go b/internal/bench/benchmark.go index 757227d..d0297fa 100644 --- a/internal/bench/benchmark.go +++ b/internal/bench/benchmark.go @@ -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 @@ -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())