Unleash / unleash-client-go

Unleash client SDK for Go
https://docs.getunleash.io
Apache License 2.0
138 stars 55 forks source link

test: benchmark feature toggle evaluation #138

Closed nunogois closed 1 year ago

nunogois commented 1 year ago

After discussing with @gardleopard we were interested in a naïve and simple benchmark for feature toggle evaluation in a language like Go.

This can be ran with a command like: go test -run=^$ -bench=BenchmarkFeatureToggleEvaluation -benchtime=10s

Here's an example of how the output could look like:

❯ go test -run=^$ -bench=BenchmarkFeatureToggleEvaluation -benchtime=10s goos: darwin goarch: arm64 pkg: github.com/Unleash/unleash-client-go/v3 BenchmarkFeatureToggleEvaluation-8 Final Estimated Operations Per Day: 101.131 billion (1.011315e+11) 13635154 854.3 ns/op PASS ok github.com/Unleash/unleash-client-go/v3 13.388s

The -8 in BenchmarkFeatureToggleEvaluation-8 stands for 8 cores (all the cores in my M1 CPU). Clarification: This version of the code is actually only using 1 core, no parallelism.

I couldn't find a way of initializing our Unleash client without a listener, so I added a simple NoOpListener.

nunogois commented 1 year ago

We tested this together and I love it! Would be good to add the how to run this in the README.md as well.

Added a new mention to the benchmark in the README, let me know what you think. Addressed in https://github.com/Unleash/unleash-client-go/pull/138/commits/b9dc62449ffb3413ba9468646a112064e58c2a0c