Skip to content

uhstray-io/nerdwa.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nerdwars

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.

How it works

  • 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.

Running Tests

Run all tests:

go test

Run tests with verbose output:

go test -v

Run a specific test function:

go test -run=TestIntMinTableDriven

Benchmarks

Run all benchmarks:

go test -bench=.

Run a specific benchmark:

go test -bench=BenchmarkIntMin

Profiling

Run 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.prof

Run a benchmark with memory profiling:

go test -bench=BenchmarkIntMin -memprofile=mem.prof

View CPU profile:

go tool pprof cpu.prof

View memory profile:

go tool pprof mem.prof

Run the benchmark with memory allocation statistics (without running tests):

go test -benchmem -run=^$ -bench ^BenchmarkIntMin$ nerdwa.rs

The -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

Contributing

  1. Add your function implementation and corresponding tests/benchmarks.
  2. Follow the table-driven test and benchmark patterns in intmin_test.go.
  3. Submit a pull request with your changes.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages