mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-28 15:02:28 +00:00
0210c5fd92
This patch contains the result of running `go fix ./...`, which applies simplifications that make use of modern language features. There are no logic or behaviour changes.
58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
package nettrace
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// Our benchmark loop is similar to the one from golang.org/x/net/trace, so we
|
|
// can compare results.
|
|
func runBench(b *testing.B, events int) {
|
|
nTraces := (b.N + events + 1) / events
|
|
|
|
for range nTraces {
|
|
tr := New("bench", "test")
|
|
for j := range events {
|
|
tr.Printf("%d", j)
|
|
}
|
|
tr.Finish()
|
|
}
|
|
}
|
|
|
|
func BenchmarkTrace_2(b *testing.B) {
|
|
runBench(b, 2)
|
|
}
|
|
|
|
func BenchmarkTrace_10(b *testing.B) {
|
|
runBench(b, 10)
|
|
}
|
|
|
|
func BenchmarkTrace_100(b *testing.B) {
|
|
runBench(b, 100)
|
|
}
|
|
|
|
func BenchmarkTrace_1000(b *testing.B) {
|
|
runBench(b, 1000)
|
|
}
|
|
|
|
func BenchmarkTrace_10000(b *testing.B) {
|
|
runBench(b, 10000)
|
|
}
|
|
|
|
func BenchmarkNewAndFinish(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
tr := New("bench", "test")
|
|
tr.Finish()
|
|
}
|
|
}
|
|
|
|
func BenchmarkPrintf(b *testing.B) {
|
|
tr := New("bench", "test")
|
|
defer tr.Finish()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
// Keep this without any formatting, so we measure our code instead of
|
|
// the performance of fmt.Sprintf.
|
|
tr.Printf("this is printf")
|
|
}
|
|
}
|