Skip to content

Commit

Permalink
trim prefixes (#20)
Browse files Browse the repository at this point in the history
during e2e command execution all files contain same prefix, this fix trims that prefix
closes #19

Signed-off-by: lwsanty <[email protected]>
  • Loading branch information
lwsanty authored Jul 31, 2019
1 parent 6f033d5 commit c610584
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/bblfsh-performance/endtoend/endtoend.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bblfsh-performance end-to-end --language=go --commit=3d9682b --filter-prefix="be
if err != nil {
return errBenchmark.New(f, err)
}
benchmarks = append(benchmarks, performance.BenchmarkResultToBenchmark(f, bRes))
benchmarks = append(benchmarks, performance.BenchmarkResultToBenchmark(f, bRes, filterPrefix))
}

// store data
Expand Down
13 changes: 8 additions & 5 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,28 @@ type Benchmark struct {
}

// NewBenchmark is a constructor for Benchmark
func NewBenchmark(pb *parse.Benchmark) Benchmark {
pb.Name = parseBenchmarkName(pb.Name)
func NewBenchmark(pb *parse.Benchmark, trimPrefixes ...string) Benchmark {
pb.Name = parseBenchmarkName(pb.Name, trimPrefixes...)
return Benchmark{*pb}
}

// BenchmarkResultToBenchmark converts b *testing.BenchmarkResult *parse.Benchmark for further storing
func BenchmarkResultToBenchmark(name string, b *testing.BenchmarkResult) Benchmark {
func BenchmarkResultToBenchmark(name string, b *testing.BenchmarkResult, trimPrefixes ...string) Benchmark {
return NewBenchmark(&parse.Benchmark{
Name: name,
N: b.N,
NsPerOp: float64(b.NsPerOp()),
AllocedBytesPerOp: uint64(b.AllocedBytesPerOp()),
AllocsPerOp: uint64(b.AllocsPerOp()),
})
}, trimPrefixes...)
}

// parseBenchmarkName removes the path and suffixes from benchmark info
// Example: BenchmarkGoDriver/transform/accumulator_factory-4 -> accumulator_factory
func parseBenchmarkName(name string) string {
func parseBenchmarkName(name string, trimPrefixes ...string) string {
for _, tp := range trimPrefixes {
name = strings.TrimPrefix(name, tp)
}
if i := strings.LastIndex(name, "/"); i >= 0 {
name = name[i+1:]
}
Expand Down

0 comments on commit c610584

Please sign in to comment.