/benchttp-sdk

A Go SDK to run benchmark and tests on HTTP endpoints.

Primary LanguageGoOtherNOASSERTION

benchttp/engine

Github Worklow Status Code coverage Go Report Card
Go package Reference Latest version

About

Benchttp engine is a Go library providing a way to perform benchmarks and tests on HTTP endpoints.

Installation

Prerequisites

Go1.17 environment or higher is required.

Install.

go get github.com/benchttp/engine

Usage

Basic usage

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)
}

Usage with JSON config via configparse

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!)

Development

Prerequisites

  1. Go 1.17 or higher is required
  2. Golangci-lint for linting files

Main commands

Command Description
make lint Runs lint on the codebase
make tests Runs tests suites from all packages
make check Runs both lint and tests