Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optionally omit the Route from the request context
Optionally save 3 allocations worth 448B per request with no vars. ``` $ go test -benchmem -benchtime 5000000x -bench BenchmarkMuxSimple goos: linux goarch: amd64 pkg: github.com/gorilla/mux cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkMuxSimple/default-8 5000000 349.3 ns/op 496 B/op 4 allocs/op BenchmarkMuxSimple/omit_route_from_ctx-8 5000000 157.8 ns/op 48 B/op 1 allocs/op PASS ok github.com/gorilla/mux 2.556s $ go test -benchmem -benchtime 5000000x -bench BenchmarkMuxSimple goos: linux goarch: amd64 pkg: github.com/gorilla/mux cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkMuxSimple/default-8 5000000 354.7 ns/op 496 B/op 4 allocs/op BenchmarkMuxSimple/omit_route_from_ctx-8 5000000 160.8 ns/op 48 B/op 1 allocs/op PASS ok github.com/gorilla/mux 2.602s $ go test -benchmem -benchtime 5000000x -bench BenchmarkMuxSimple goos: linux goarch: amd64 pkg: github.com/gorilla/mux cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkMuxSimple/default-8 5000000 376.4 ns/op 496 B/op 4 allocs/op BenchmarkMuxSimple/omit_route_from_ctx-8 5000000 168.1 ns/op 48 B/op 1 allocs/op PASS ok github.com/gorilla/mux 2.745s ``` ``` $ go test -benchmem -benchtime 5000000x -bench BenchmarkPopulateContext goos: linux goarch: amd64 pkg: github.com/gorilla/mux cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkPopulateContext/no_populated_vars-8 5000000 381.6 ns/op 496 B/op 4 allocs/op BenchmarkPopulateContext/empty_var-8 5000000 913.6 ns/op 928 B/op 9 allocs/op BenchmarkPopulateContext/populated_vars-8 5000000 914.0 ns/op 912 B/op 8 allocs/op BenchmarkPopulateContext/omit_route_/static-8 5000000 168.6 ns/op 48 B/op 1 allocs/op BenchmarkPopulateContext/omit_route_/dynamic-8 5000000 827.4 ns/op 880 B/op 8 allocs/op PASS ok github.com/gorilla/mux 16.049s ``` Signed-off-by: Jakob Ackermann <[email protected]>
- Loading branch information