Benchttp engine is a Go library providing a way to perform benchmarks and tests on HTTP endpoints.
Go1.17 environment or higher is required.
Install.
go get github.com/benchttp/engine
package main
import (
"context"
"fmt"
"github.com/benchttp/engine/benchttp"
)
func main() {
report, _ := benchttp.
DefaultRunner(). // Default runner with safe configuration
WithNewRequest("GET", "http://localhost:3000", nil). // Attach request
Run(context.Background()) // Run benchmark, retrieve report
fmt.Println(report.Metrics.ResponseTimes.Mean)
}
package main
import (
"context"
"fmt"
"github.com/benchttp/engine/benchttp"
"github.com/benchttp/engine/configio"
)
func main() {
// JSON configuration obtained via e.g. a file or HTTP call
jsonConfig := []byte(`
{
"request": {
"url": "http://localhost:3000"
}
}`)
// Instantiate a base Runner (here the default with a safe configuration)
runner := benchttp.DefaultRunner()
// Parse the json configuration into the Runner
_ = configio.UnmarshalJSONRunner(jsonConfig, &runner)
// Run benchmark, retrieve report
report, _ := runner.Run(context.Background())
fmt.Println(report.Metrics.ResponseTimes.Mean)
}
📄 Please refer to our Wiki for exhaustive Runner
and Report
structures (and more!)
- Go 1.17 or higher is required
- Golangci-lint for linting files
Command | Description |
---|---|
./script/lint |
Runs lint on the codebase |
./script/test |
Runs tests suites from all packages |
./script/doc |
Serves Go doc for this module at localhost:9995 |