bench

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BenchResult

type BenchResult struct {
	URL            string
	TotalReqs      int64
	SuccessReqs    int64
	FailReqs       int64
	Duration       time.Duration
	AvgRespTime    time.Duration
	MinRespTime    time.Duration
	MaxRespTime    time.Duration
	ReqsPerSecond  float64
	BytesPerSecond float64
	StatusCodes    map[int]int64
}

BenchResult 保存测试结果

func (*BenchResult) String

func (r *BenchResult) String() string

String 格式化输出结果

type HTTPBench

type HTTPBench struct {
	// 基础配置
	URL      string
	Method   string
	Headers  map[string]string
	Body     []byte
	Timeout  time.Duration // 每个请求的超时时间
	QPSLimit int           // QPS限制 (0表示不限制)

	// 测试参数
	Number      int           // 总请求数
	Concurrency int           // 并发数
	Duration    time.Duration // 测试时长 (如果指定,则忽略Number)
	// contains filtered or unexported fields
}

HTTPBench 实现类似 apache bench 的测试功能

func NewHTTPBench

func NewHTTPBench(url string) *HTTPBench

NewHTTPBench 创建新的HTTPBench实例

func (*HTTPBench) Run

func (b *HTTPBench) Run() (*BenchResult, error)

Run 执行基准测试

func (*HTTPBench) SetBody

func (b *HTTPBench) SetBody(body []byte) *HTTPBench

SetBody 设置请求体

func (*HTTPBench) SetConcurrency

func (b *HTTPBench) SetConcurrency(concurrency int) *HTTPBench

SetConcurrency 设置并发数

func (*HTTPBench) SetDuration

func (b *HTTPBench) SetDuration(duration time.Duration) *HTTPBench

SetDuration 设置测试时长

func (*HTTPBench) SetHeaders

func (b *HTTPBench) SetHeaders(headers map[string]string) *HTTPBench

SetHeaders 设置请求头

func (*HTTPBench) SetMethod

func (b *HTTPBench) SetMethod(method string) *HTTPBench

SetMethod 设置HTTP方法

func (*HTTPBench) SetNumber

func (b *HTTPBench) SetNumber(number int) *HTTPBench

SetNumber 设置请求数

func (*HTTPBench) SetQPSLimit

func (b *HTTPBench) SetQPSLimit(qps int) *HTTPBench

SetQPSLimit 设置QPS限制

func (*HTTPBench) SetShowProgress

func (b *HTTPBench) SetShowProgress(show bool) *HTTPBench

SetShowProgress 设置是否显示进度条

func (*HTTPBench) SetTimeout

func (b *HTTPBench) SetTimeout(timeout time.Duration) *HTTPBench

SetTimeout 设置超时时间

Jump to

Keyboard shortcuts

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