git » gofer » commit 831794d

nettrace: Add benchmarks for New/Finish, and Printf

author Alberto Bertogli
2022-09-25 17:23:49 UTC
committer Alberto Bertogli
2022-10-07 10:59:43 UTC
parent 2cbf4e7762811d04887ade7e7edb935cc1af9a3a

nettrace: Add benchmarks for New/Finish, and Printf

nettrace/bench_test.go +18 -0

diff --git a/nettrace/bench_test.go b/nettrace/bench_test.go
index d6bbcbb..a58fdbb 100644
--- a/nettrace/bench_test.go
+++ b/nettrace/bench_test.go
@@ -37,3 +37,21 @@ func BenchmarkTrace_1000(b *testing.B) {
 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")
+	}
+}