• Stars
    star
    382
  • Rank 108,817 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Continuous Benchmark for Go Project

GitHub release Go Report Card MIT License

Abstract

cob compares benchmarks between the latest commit (HEAD) and the previous commit (HEAD{@1}). The program will fail if the change in score is worse than the threshold. This tools is suitable for CI/CD to detect a regression of a performance automatically.

cob runs go test -bench before and after commit internally, so it depends on go command.

CAUTION: Note that git reset is executed when you run cob. You should commit all changes before running cob.

Table of Contents

Continuous Integration (CI)

See cob-example for details.

GitHub Actions

name: Bench
on: [push, pull_request]
jobs:
  test:
    name: Bench
    runs-on: ubuntu-latest
    steps:

    - name: Set up Go 1.13
      uses: actions/setup-go@v1
      with:
        go-version: 1.13
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v1

    - name: Install cob
      run: curl -sfL https://raw.githubusercontent.com/knqyf263/cob/master/install.sh | sudo sh -s -- -b /usr/local/bin

    - name: Run Benchmark
      run: cob

Travis CI

dist: bionic
language: go
go:
  - 1.13.x

before_script:
  - curl -sfL https://raw.githubusercontent.com/knqyf263/cob/master/install.sh | sudo sh -s -- -b /usr/local/bin

script:
  - cob

CircleCI

version: 2
jobs:
  bench:
    docker:
      - image: circleci/golang:1.13
    steps:
      - checkout
      - run:
          name: Install cob
          command: curl -sfL https://raw.githubusercontent.com/knqyf263/cob/master/install.sh | sudo sh -s -- -b /usr/local/bin
      - run:
          name: Run cob
          command: cob
workflows:
  version: 2
  build-workflow:
    jobs:
      - bench

Example

Override a command to measure benchmarks

To measure benchmarks by make bench, you can use -bench-cmd and -bench-args options.

$ cob -bench-cmd make -bench-args bench

Run only those benchmarks matching a regular expression

$ cob -bench-args "test -bench Append -benchmem ./..."
Result
2020/01/12 17:32:30 Run Benchmark: 4363944cbed3da7a8245cbcdc8d8240b8976eb24 HEAD{@1}
2020/01/12 17:32:32 Run Benchmark: 599a5523729d4d99a331b9d3f71dde9e1e6daef0 HEAD

Result
======

+-----------------------------+----------+---------------+-------------------+
|            Name             |  Commit  |    NsPerOp    | AllocedBytesPerOp |
+-----------------------------+----------+---------------+-------------------+
| BenchmarkAppend_Allocate-16 |   HEAD   |  179.00 ns/op |      117 B/op     |
+                             +----------+---------------+-------------------+
|                             | HEAD@{1} |  115.00 ns/op |      23 B/op      |
+-----------------------------+----------+---------------+-------------------+

Comparison
==========

+-----------------------------+---------+-------------------+
|            Name             | NsPerOp | AllocedBytesPerOp |
+-----------------------------+---------+-------------------+
| BenchmarkAppend_Allocate-16 | 55.65%  |      408.70%      |
+-----------------------------+---------+-------------------+

Show only benchmarks with worse score

$ cob -only-degression
Result
2020/01/12 17:48:35 Run Benchmark: 4363944cbed3da7a8245cbcdc8d8240b8976eb24 HEAD{@1}
2020/01/12 17:48:38 Run Benchmark: 599a5523729d4d99a331b9d3f71dde9e1e6daef0 HEAD

Comparison
==========

+-----------------------------+---------+-------------------+
|            Name             | NsPerOp | AllocedBytesPerOp |
+-----------------------------+---------+-------------------+
| BenchmarkAppend_Allocate-16 | 52.34%  |      347.83%      |
+-----------------------------+---------+-------------------+

2020/01/12 17:48:39 This commit makes benchmarks worse

Specify a threshold

The following option means the program fails if a benchmark score gets worse than 50%.

$ 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 ./...

Compare only memory allocation

You can use -compare option.

$ cob -compare B/op
Result
2020/01/15 14:46:31 Run Benchmark: 4363944cbed3da7a8245cbcdc8d8240b8976eb24 HEAD~1
2020/01/15 14:46:33 Run Benchmark: 599a5523729d4d99a331b9d3f71dde9e1e6daef0 HEAD

Result
======

+-----------------------------+----------+---------------+-------------------+
|            Name             |  Commit  |    NsPerOp    | AllocedBytesPerOp |
+-----------------------------+----------+---------------+-------------------+
| BenchmarkAppend_Allocate-16 |   HEAD   |  179.00 ns/op |      121 B/op     |
+                             +----------+---------------+-------------------+
|                             | HEAD@{1} |  104.00 ns/op |      23 B/op      |
+-----------------------------+----------+---------------+-------------------+
|      BenchmarkCall-16       |   HEAD   |   0.50 ns/op  |       0 B/op      |
+                             +----------+---------------+                   +
|                             | HEAD@{1} |   0.49 ns/op  |                   |
+-----------------------------+----------+---------------+-------------------+

Comparison
==========

+-----------------------------+---------+-------------------+
|            Name             | NsPerOp | AllocedBytesPerOp |
+-----------------------------+---------+-------------------+
| BenchmarkAppend_Allocate-16 |    -    |      426.09%      |
+-----------------------------+---------+-------------------+
|      BenchmarkCall-16       |    -    |       0.00%       |
+-----------------------------+---------+-------------------+

2020/01/15 14:46:35 This commit makes benchmarks worse

Skip running cob

If your commit message contains [skip cob], cob is skipped.

$ git add README.md
$ git commit -m "[skip cob] update README.md"
$ cob
2020/04/19 12:46:57 [skip cob] is detected, so the benchmark is skipped

Usage

NAME:
   cob - Continuous Benchmark for Go project

USAGE:
   cob [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --only-degression   Show only benchmarks with worse score (default: false)
   --threshold value   The program fails if the benchmark gets worse than the threshold (default: 0.2)
   --base value        Specify a base commit compared with HEAD (default: "HEAD~1")
   --compare value     Which score to compare (default: "ns/op,B/op")
   --bench-cmd value   Specify a command to measure benchmarks (default: "go")
   --bench-args value  Specify arguments passed to -cmd (default: "test -run '^$' -bench . -benchmem ./...")
   --help, -h          show help (default: false)

Q&A

Benchmarks with the same name

Specify a package name.

$ cob -bench-args "test -bench . -benchmem ./foo" 
$ cob -bench-args "test -bench . -benchmem ./bar" 

A result of benchmarks is unstable

You can specify -benchtime.

$ cob -bench-args "test -bench . -benchmem -benchtime 10s ./..." 

License

This repository is available under the MIT

Author

Teppei Fukuda (knqyf263)

More Repositories

1

pet

Simple command-line snippet manager
Go
4,159
star
2

go-plugin

Go Plugin System over WebAssembly
Go
529
star
3

utern

Multi group and stream log tailing for AWS CloudWatch Logs.
Go
306
star
4

dnspooq

DNSpooq - dnsmasq cache poisoning (CVE-2020-25686, CVE-2020-25684, CVE-2020-25685)
Python
92
star
5

go-rpmdb

RPM DB bindings for go
Go
56
star
6

CVE-2022-0847

The Dirty Pipe Vulnerability
Go
47
star
7

CVE-2020-8617

PoC for CVE-2020-8617 (BIND)
Dockerfile
47
star
8

CVE-2019-6340

Environment for CVE-2019-6340 (Drupal)
Dockerfile
42
star
9

CVE-2021-40346

CVE-2021-40346 PoC (HAProxy HTTP Smuggling)
JavaScript
38
star
10

CVE-2023-50387

KeyTrap (DNSSEC)
Dockerfile
36
star
11

crtsh

API client for crt.sh
Go
31
star
12

go-deb-version

A golang library for parsing deb package versions
Go
29
star
13

CVE-2019-6467

CVE-2019-6467 (BIND nxdomain-redirect)
Dockerfile
28
star
14

azaws

Save temporary security credentials of AWS via Azure AD SSO
Go
28
star
15

CVE-2020-10749

CVE-2020-10749 PoC (Kubernetes MitM attacks via IPv6 rogue router advertisements)
Python
27
star
16

go-cpe

A Go library for CPE (A Common Platform Enumeration 2.3)
Go
26
star
17

remic

Vulnerability Scanner for Detecting Publicly Disclosed Vulnerabilities in Application Dependencies
Go
24
star
18

ndff

A flow-based network monitor with Deep Packet Inspection
C
24
star
19

trivy-issue-action

GitHub Actions for creating GitHub Issues according to the Trivy scanning result
Shell
23
star
20

go-rpm-version

A golang library for parsing rpm package versions
Go
20
star
21

CVE-2020-7461

PoC for DHCP vulnerability (NAME:WRECK) in FreeBSD
Python
15
star
22

CVE-2021-3129

PoC for CVE-2021-3129 (Laravel)
Python
14
star
23

CVE-2018-1111

Environment for DynoRoot (CVE-2018-1111)
Shell
14
star
24

CVE-2021-41773

Path traversal in Apache HTTP Server 2.4.49 (CVE-2021-41773)
Dockerfile
11
star
25

CVE-2018-6389

WordPress DoS (CVE-2018-6389)
10
star
26

CVE-2018-1273

Environment for CVE-2018-1273 (Spring Data Commons)
Dockerfile
9
star
27

nested

Easier way to handle the nested data structure
Go
9
star
28

repacker

Automate the creation of methods that copy from src struct to target struct
Go
8
star
29

CVE-2019-5420

CVE-2019-5420 (Ruby on Rails)
Dockerfile
8
star
30

holiday_jp-go

Japanese holiday
Go
7
star
31

go-apk-version

A golang library for parsing apk package versions
Go
7
star
32

osbpsql

An implementation of the Open Service Broker API for PostgreSQL
Go
7
star
33

stargz-registry

Go
5
star
34

gzip2zip

Gzip to ZIP on-the-fly
Go
4
star
35

redis-rogue-server

Redis Rogue Server
Python
4
star
36

CVE-2018-16509

CVE-2018-16509 (Ghostscript contains multiple -dSAFER sandbox bypass vulnerabilities)
Dockerfile
4
star
37

CVE-2018-11776

Environment for CVE-2018-11776 / S2-057 (Apache Struts 2)
Python
4
star
38

CVE-2018-1304

Java
3
star
39

trivy-aws-enforcer

Go
3
star
40

CVE-2018-7600

CVE-2018-7600 (Drupal)
Python
3
star
41

redis-post-exploitation

Dockerfile
3
star
42

apkindex-archive

Archive for APKINDEX
Python
3
star
43

sshtrace

Go
2
star
44

ssm-to-vuls

Collect package list from AWS System Manager and Send them to Vuls server
Python
2
star
45

nxdomain-redirect

Dockerfile
2
star
46

ssrfnginx

1
star
47

CVE-2018-6376

Joomla!, Second Order SQL Injection
1
star
48

presentation

Python
1
star
49

redis-exploitation

CONFIG SET
Dockerfile
1
star
50

setup-softether

for setup SoftEtherVPN
Shell
1
star
51

zig-wasm-example

Zig + Wasm + wazero
Go
1
star
52

cve-2015-5477

PoC for BIND9 TKEY assert DoS (CVE-2015-5477)
Python
1
star
53

rasm

Wasm runtime written in Rust
Rust
1
star
54

alma

Alma is an open-source Alert Manager with DSL
Ruby
1
star