Home / File/ request_bench_test.go — fiber Source File

request_bench_test.go — fiber Source File

Architecture documentation for request_bench_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberClient Hooks 1 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  21fe2c98_fc8d_efc8_6a15_e37ab0542e3c["request_bench_test.go"]
  377137ab_30ab_8a47_264c_088b7eef75eb["runtime"]
  21fe2c98_fc8d_efc8_6a15_e37ab0542e3c --> 377137ab_30ab_8a47_264c_088b7eef75eb
  style 21fe2c98_fc8d_efc8_6a15_e37ab0542e3c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package client

import (
	"runtime"
	"runtime/metrics"
	"strconv"
	"testing"
)

// BenchmarkRequestHeapScan measures how much heap memory the GC needs to scan
// when a batch of requests is created and released.
func BenchmarkRequestHeapScan(b *testing.B) {
	samples := []metrics.Sample{
		{Name: "/gc/scan/heap:bytes"},
		{Name: "/gc/scan/total:bytes"},
	}

	b.ReportAllocs()
	b.StopTimer()
	b.ResetTimer()

	const batchSize = 512
	var totalScanHeap, totalScanAll uint64
	for i := 0; i < b.N; i++ {
		reqs := make([]*Request, batchSize)
		// revive:disable-next-line:call-to-gc // Ensure consistent heap state before measuring scan metrics
		runtime.GC()
		metrics.Read(samples)
		startScanHeap := samples[0].Value.Uint64()
		startScanAll := samples[1].Value.Uint64()

		b.StartTimer()
		for j := range reqs {
			req := AcquireRequest()
			req.SetHeader("X-Benchmark", "value")
			req.SetCookie("session", strconv.Itoa(j))
			req.SetPathParam("id", strconv.Itoa(j))
			req.SetParam("page", strconv.Itoa(j))
			reqs[j] = req
		}
		b.StopTimer()

		// revive:disable-next-line:call-to-gc // Force GC to capture post-benchmark scan metrics
		runtime.GC()
		metrics.Read(samples)
		totalScanHeap += samples[0].Value.Uint64() - startScanHeap
		totalScanAll += samples[1].Value.Uint64() - startScanAll

		for _, req := range reqs {
			ReleaseRequest(req)
		}
	}

	if b.N > 0 {
		b.ReportMetric(float64(totalScanHeap)/float64(b.N), "scan-bytes-heap/op")
		b.ReportMetric(float64(totalScanAll)/float64(b.N), "scan-bytes-total/op")
	}
}

Domain

Subdomains

Classes

Dependencies

  • runtime

Frequently Asked Questions

What does request_bench_test.go do?
request_bench_test.go is a source file in the fiber codebase, written in go. It belongs to the FiberClient domain, Hooks subdomain.
What functions are defined in request_bench_test.go?
request_bench_test.go defines 1 function(s): BenchmarkRequestHeapScan.
What does request_bench_test.go depend on?
request_bench_test.go imports 1 module(s): runtime.
Where is request_bench_test.go in the architecture?
request_bench_test.go is located at client/request_bench_test.go (domain: FiberClient, subdomain: Hooks, directory: client).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free