I am practicing my Golang by writing a simple Redis clone.
How do i write a benchmark script that would establish X connections per second at C concurrency level to deal with my server's protocol and measure how many ops/sec?
I can simply write a script that would actually do this:
print('\n'*40 + '*'*80)
But i want to know the concept behind distributing the number of connections per concurrency level per second.
答案 0 :(得分:7)
This is best handled by the built-in testing.Benchmark
system. For example, a test case like:
git clone https://username@github.com/username/repository
will automatically work out timing calculations for this function. See the package documentation for more details on setting it up, but it should be very familiar if you've written Go test cases before.
To your question about concurrency benchmarking, see the func BenchmarkHello(b *testing.B) {
for i := 0; i < b.N; i++ {
fmt.Sprintf("hello")
}
}
helper, which is specifically to assist in this.