package module
Version: v0.0.0-...-cc39d11 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2015 License: MIT Imports: 13 Imported by: 0




Package benchserve provides a simple benchmark server.

It is designed to allow an external program to drive the benchmarks in a compiled test binary.

The API and protocol is still under development and may change.

To enable benchserve with a package, add this somewhere to your package's tests:

import ""

func TestMain(m *testing.M) {

Your existing tests and benchmarks will operate unchanged. To use benchserve, compile the tests with 'go test -c', and then execute with the -test.benchserve flag, e.g. './foo.test -test.benchserve'. This will bypass all tests and benchmarks and ignore all other flags, including the usual benchmarking and profiling flags, and instead start the benchmark server.

The benchmark server uses JSON-RPC. By default, it listens on :52525. Use the -test.benchserve.addr flag to set a different host:port. The server only serves a single request at a time. Serving requests concurrency could skew benchmark results.

Benchserve relies on unexported details of the testing package, which may change at any time. A request to officially support this functionality is



This section is empty.


This section is empty.


func Main

func Main(m *testing.M)

Main runs a test binary. To incorporate benchserve into your package, add this TestMain function:

func TestMain(m *testing.M) {

If your package already has a TestMain, use Serve.

func Serve

func Serve(m *testing.M)

Serve starts a new benchmark server using the benchmarks contained in m if the test.benchserve flag is set. Otherwise, Serve is a no-op.

Serve should only be used in packages that already have a custom TestMain function. Most packages should use Main instead.

To use Serve, call it from TestMain after calling flag.Parse, after any required benchmarking setup has completed, but before any tests or benchmarks have been run. For example:

	func TestMain(m *testing.M) {
 	// do any setup that is necessary for benchmarking
		benchserve.Serve() // if flag is set, does not return; if flag is not set, no-op
		// run tests, etc.


type Options

type Options struct {
	Benchmem bool // equivalent to -test.benchmem

Options control benchmarking behavior.

type Result

type Result struct {

	// ReportAllocs reports whether allocations should be reported for this run.
	// This might be set as a result of the current Options
	// or because the benchmark called b.ReportAllocs.
	ReportAllocs bool
	// contains filtered or unexported fields

Result is the result of a single benchmark run.

type Run

type Run struct {
	Name  string // name of the benchmark to run
	Procs int    // GOMAXPROCS value, equivalent to -test.cpu
	N     int    // number of iterations to run, equivalent to b.N

Run requests a single benchmark run.

type Server

type Server struct {
	// contains filtered or unexported fields

Server is a benchmark server. It handles JSON-RPC requests.

func (*Server) Kill

func (s *Server) Kill(args struct{}, reply *struct{}) error

Kill stops the benchmark server and its process.

func (*Server) List

func (s *Server) List(args struct{}, names *[]string) error

List returns an unordered list of the available benchmark names.

func (*Server) Run

func (s *Server) Run(args Run, reply *Result) error

Run runs a single benchmark.

func (*Server) Set

func (s *Server) Set(args Options, reply *struct{}) error

Set sets the server's Options.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL