stats

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 7 Imported by: 35

README

stats

PkgGoDev Build Status codecov Go Report Card GitHub release LICENSE

Package stats implements a generic benchmarking tool.

Get started

Install
go get github.com/hslam/stats
Import
import "github.com/hslam/stats"
Example
package main

import (
	"github.com/hslam/stats"
	"math/rand"
	"time"
)

func main() {
	var Clients []stats.Client
	for i := 0; i < 1e2; i++ {
		Clients = append(Clients, &Client{})
	}
	parallel := 32
	totalCalls := 1000000
	stats.StartPrint(parallel, totalCalls, Clients)
}

type Client struct {
}

func (c *Client) Call() (int64, int64, bool) {
	time.Sleep(time.Microsecond * time.Duration(rand.Intn(1000)))
	if rand.Intn(1000) == 1 {
		return 1e3, 0, false
	}
	return 1e3, 1e3, true
}
Output
Summary:
	Clients:	100
	Parallel calls per client:	32
	Total calls:	1000000
	Total time:	0.70s
	Requests per second:	1427276.68
	Fastest time for request:	0.00ms
	Average time per request:	2.19ms
	Slowest time for request:	16.67ms

Time:
	0.1%	time for request:	0.00ms
	1%	time for request:	0.46ms
	5%	time for request:	0.71ms
	10%	time for request:	0.89ms
	25%	time for request:	1.32ms
	50%	time for request:	2.00ms
	75%	time for request:	2.78ms
	90%	time for request:	3.64ms
	95%	time for request:	4.33ms
	99%	time for request:	6.43ms
	99.9%	time for request:	9.79ms

Request:
	Total request body sizes:	1000000000
	Average body size per request:	1000.00 Byte
	Request rate per second:	1427276684.72 Byte/s (1427.28 MByte/s)

Response:
	Total response body sizes:	998982000
	Average body size per response:	1000.00 Byte
	Response rate per second:	1425823717.06 Byte/s (1425.82 MByte/s)

Result:
	Response ok:	998982 (99.90%)
	Errors:	1018 (0.10%)
License

This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)

Author

stats was written by Meng Huang.

Documentation

Overview

Package stats implements a generic benchmarking tool.

Index

Constants

This section is empty.

Variables

View Source
var Bar = true

Bar is true.

Functions

func SetBar

func SetBar(bar bool)

SetBar sets bar.

func StartPrint

func StartPrint(numParallels int, totalCalls int, clients []Client)

StartPrint prints the stats result.

Types

type Client

type Client interface {
	// Call returns a request size, a response size and its ok status.
	Call() (RequestSize int64, ResponseSize int64, Ok bool)
}

Client represents a client.

type Result

type Result struct {
	Clients                    int
	Parallels                  int
	TotalCalls                 int64
	TotalTime                  float64
	RequestsPerSecond          float64
	AverageTimePerRequest      float64
	FastestTimeForRequest      float64
	SlowestTimeForRequest      float64
	N001thThousandthTime       float64
	N010thThousandthTime       float64
	N050thThousandthTime       float64
	N100thThousandthTime       float64
	N250thThousandthTime       float64
	N500thThousandthTime       float64
	N750thThousandthTime       float64
	N900thThousandthTime       float64
	N950thThousandthTime       float64
	N990thThousandthTime       float64
	N999thThousandthTime       float64
	TotalRequestBodySizes      int64
	AverageBodySizePerRequest  float64
	RequestRateBytePerSecond   float64
	RequestRateMBytePerSecond  float64
	TotalResponseBodySizes     int64
	AverageBodySizePerResponse float64
	ResponseRateBytePerSecond  float64
	ResponseRateMBytePerSecond float64
	ResponseOk                 int64
	ResponseOkPercentile       float64
	Errors                     int64
	ErrorsPercentile           float64
}

Result is a stats result.

func Start

func Start(numParallels int, totalCalls int, clients []Client) *Result

Start returns the stats result.

func (*Result) Format

func (statsResult *Result) Format() string

Format returns the formatted string.

Jump to

Keyboard shortcuts

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