Skip to content

Commit

Permalink
feat(option): add --base to specify a base commit (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored Jan 15, 2020
1 parent 9e76d1f commit 738974e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [Run only those benchmarks matching a regular expression](#run-only-those-benchmarks-matching-a-regular-expression)
- [Show only benchmarks with worse score](#show-only-benchmarks-with-worse-score)
- [Specify a threshold](#specify-a-threshold)
- [Specify a base commit compared with HEAD](#specify-a-base-commit-compared-with-head)
- [Usage](#usage)
- [Q&A](#qa)
- [A result of benchmarks is unstable](#a-result-of-benchmarks-is-unstable)
Expand Down Expand Up @@ -217,6 +218,13 @@ The following option means the program fails if a benchmark score gets worse tha
$ cob -threshold 0.5 ./...
```

## Specify a base commit compared with HEAD
By default, `cob` uses `HEAD~1`. If you compare benchmarks with different commit, you can use `--base` option.

```
$ cob --base origin/master ./...
```

# Usage

```
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type config struct {
args []string
onlyDegression bool
threshold float64
base string
bench string
benchmem bool
benchtime string
Expand All @@ -17,6 +18,7 @@ func newConfig(c *cli.Context) config {
args: c.Args().Slice(),
onlyDegression: c.Bool("only-degression"),
threshold: c.Float64("threshold"),
base: c.String("base"),
bench: c.String("bench"),
benchmem: c.Bool("benchmem"),
benchtime: c.String("benchtime"),
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os/exec"
"strings"

"gopkg.in/src-d/go-git.v4/plumbing"

"golang.org/x/xerrors"

"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -40,6 +42,11 @@ func main() {
Usage: "The program fails if the benchmark gets worse than the threshold",
Value: 0.2,
},
&cli.StringFlag{
Name: "base",
Usage: "Specify a base commit compared with HEAD",
Value: "HEAD~1",
},
&cli.StringFlag{
Name: "bench",
Usage: "Run only those benchmarks matching a regular expression.",
Expand Down Expand Up @@ -78,7 +85,7 @@ func run(c config) error {
return xerrors.Errorf("unable to get the reference where HEAD is pointing to: %w", err)
}

prev, err := r.ResolveRevision("HEAD~1")
prev, err := r.ResolveRevision(plumbing.Revision(c.base))
if err != nil {
return xerrors.Errorf("unable to resolves revision to corresponding hash: %w", err)
}
Expand All @@ -104,7 +111,7 @@ func run(c config) error {

args := prepareBenchArgs(c)

log.Printf("Run Benchmark: %s %s", prev, "HEAD{@1}")
log.Printf("Run Benchmark: %s %s", prev, c.base)
prevSet, err := runBenchmark(args)
if err != nil {
return xerrors.Errorf("failed to run a benchmark: %w", err)
Expand Down

0 comments on commit 738974e

Please sign in to comment.