Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
/ bench Public archive

Bench makes it easy to write benchmarking apps in Golang.

Notifications You must be signed in to change notification settings

chirayu/bench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bench Build Status GoDoc

Bench is a golang package to help speed up benchmarking projects. It can be used to do benchmark your database, queue or rest server.

Features

Bench can call a function repeatedly or at a uniform rate with the specificied concurrency. For each call, the called function can captures metrics, which are summarized at the end of the run.

Captured metrics include:

  • Timers. Use it to capture latency of functions, I/O bound calls.
  • Counters.

A sample run will spew similar output

$ go run simple.go
Rate: 10 calls/sec, Duration: 5.00s, Concurrency: 2, Total runs: 50
  >>Timer: Latency
    5.0th percentile: 0.59ms
    50.0th percentile: 0.67ms
    99.9th percentile: 0.82ms
    100.0th percentile: 0.82ms
  >>Counter: Call Counter
    Value: 50

Bench provides a Context in each function call. Use it to

  • Pick different between urls for each call
  • Add it as a custom header for your Rest call
  • Generate different DB data
  • Store run specific values. Example connection pools.

Usage

Bench is easy to integrate with your code. This code benchmarks a http server with a concurrency of 10 for 10 seconds by calling the benchmarkMe function continuously.

func benchmarkMe(c *bench.Context) {
	start := time.Now()
	resp, err := http.Get("http://www.flipkart.com")
	if err != nil {
		fmt.Printf("Error %s", err)
	}
	defer resp.Body.Close()
	c.RecordTime(time.Since(start))
}

func main() {
	b := bench.NewBench(10, time.Second*10, 0, benchmarkMe)
	b.Run()
	fmt.Printf("%s", b)

Here, the same function is called at a rate of 100 per second.

func main() {
	b := bench.NewBench(10, time.Second*10, 100, benchmarkMe)
	b.Run()
	fmt.Printf("%s", b)

Upcoming features

Two features are in the offing.

  1. Support for an initial calibration period during which metrics are ignored.
  2. Production quality http benchmarks.

About

Bench makes it easy to write benchmarking apps in Golang.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages