This repository is a benchmarking and testing framework for comparing multiple implementations of a function in Go. The goal is to provide a simple, extensible setup for writing, testing, and benchmarking different solutions to the same problem.
- Implement your function(s) in Go.
- Add table-driven tests to verify correctness.
- Add benchmarks to measure performance.
- Use the provided commands to run tests and benchmarks, and to profile CPU and memory usage.
Run all tests:
go testRun tests with verbose output:
go test -vRun a specific test function:
go test -run=TestIntMinTableDrivenRun all benchmarks:
go test -bench=.Run a specific benchmark:
go test -bench=BenchmarkIntMinRun a benchmark with CPU profiling: You will need graphviz installed to visualize the profiles. https://graphviz.gitlab.io/download/
go test -bench=BenchmarkIntMin -cpuprofile=cpu.profRun a benchmark with memory profiling:
go test -bench=BenchmarkIntMin -memprofile=mem.profView CPU profile:
go tool pprof cpu.profView memory profile:
go tool pprof mem.profRun the benchmark with memory allocation statistics (without running tests):
go test -benchmem -run=^$ -bench ^BenchmarkIntMin$ nerdwa.rsThe -run=^$ flag tells the go test command to run no tests, effectively skipping the test phase and only running benchmarks.
The -benchmem flag enables memory allocation statistics for the benchmarks.
The -bench ^BenchmarkIntMin$ flag specifies that only the BenchmarkIntMin benchmark should be executed.
The ^ and $ symbols are Regex anchors that ensure an exact match for the benchmark name.
Run a specific benchmark in the exercises/1 directory:
go test ./exercises/1/... -bench=BenchmarkIntMin- Add your function implementation and corresponding tests/benchmarks.
- Follow the table-driven test and benchmark patterns in
intmin_test.go. - Submit a pull request with your changes.
MIT