benchmarking

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectFuncToComplete deprecated

func ExpectFuncToComplete(f func(), runtimeThresholdInSeconds float64)

ONLY COMPILES ON LINUX most often you will want to wrap the code being tested (i.e., f()) in a for loop to get more sizeable readings. use this function over built-in benchmarker (https://onsi.github.io/ginkgo/#benchmark_tests) to measure time using the OS user-time specific to the executing thread. This _should_ help with noisy neighbors in ci/locally.

other things to note while benchmarking:

  • I've noticed the google cloudbuild hardware matters a lot, using nonstandard hardware (e.g. `N1_HIGHCPU_8`) has helped improve reliability of benchmarks
  • we could still explore running tests with nice and/or ionice
  • could also further explore running the tests with docker flags --cpu-shares set

Deprecated: use Measure instead.

func TimeForFuncToComplete added in v0.21.18

func TimeForFuncToComplete(f func()) float64

TimeForFuncToComplete returns the time the given function spend executing in user mode. Deprecated: use Measure instead.

Types

type Result added in v0.24.1

type Result struct {
	// Time spent in user mode
	Utime time.Duration
	// Time spent in kernel mode
	Stime time.Duration
	// Time spent in user mode + kernel mode
	Total time.Duration
}

Result represents the result of measuring a function's execution time.

func Measure added in v0.24.1

func Measure(f func()) (Result, error)

Measure returns the time it took to execute the given function. It only compiles on Linux. Most often you will want to run the code you want to test in a loop to get more sizeable readings, e.g.:

results := benchmarking.Measure(func() {
	for i := 0; i < 100; i++ {
		funcToTest()
	}
})

Measure should be preferred over the Gomega benchmark utils (https://pkg.go.dev/github.com/onsi/gomega/gmeasure) as it takes some additional steps to ensure we get accurate measurements.

Further ideas for improvement:

  • we could explore running tests with nice and/or ionice
  • could also further explore running the tests with docker flags --cpu-shares set
  • consider setting GOMAXPROCS when running the tests to ensure we run in a single thread

Jump to

Keyboard shortcuts

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