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/runner"
)
func main(t *testing.T) {
// Set runner configuration
config := runner.DefaultConfig()
config.Request = config.Request.WithURL("https://example.com")
// Instantiate runner and run benchmark
report, _ := runner.New(nil).Run(context.Background(), config)
fmt.Println(report.Metrics.ResponseTimes.Mean)
}
package main
import (
"context"
"fmt"
"github.com/benchttp/engine/configparse"
"github.com/benchttp/engine/runner"
)
func main() {
// JSON configuration obtained via e.g. a file or HTTP call
jsonConfig := []byte(`
{
"request": {
"url": "https://example.com"
}
}`)
config, _ := configparse.JSON(jsonConfig)
report, _ := runner.New(nil).Run(context.Background(), config)
fmt.Println(report.Metrics.ResponseTimes.Mean)
}
📄 Please refer to our Wiki for exhaustive Config
and Report
structures (and more!)
- Go 1.17 or higher is required
- Golangci-lint for linting files
Command | Description |
---|---|
make lint |
Runs lint on the codebase |
make tests |
Runs tests suites from all packages |
make check |
Runs both lint and tests |