From fe33c05a20d49fb934bfd28b8f223554bc8fc859 Mon Sep 17 00:00:00 2001 From: Matthew Dawson Date: Sun, 21 Jan 2018 23:26:47 -0500 Subject: [PATCH] debug/log: Add benchmarks for calling the logging function Add some benchmarks for calling Log, both with a static string along with calling the ID.Str and ID.String functions. --- internal/debug/log_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 internal/debug/log_test.go diff --git a/internal/debug/log_test.go b/internal/debug/log_test.go new file mode 100644 index 000000000..647e16e85 --- /dev/null +++ b/internal/debug/log_test.go @@ -0,0 +1,34 @@ +package debug_test + +import ( + "github.com/restic/restic/internal/debug" + "github.com/restic/restic/internal/restic" + + "testing" +) + +func BenchmarkLogStatic(b *testing.B) { + for i := 0; i < b.N; i++ { + debug.Log("Static string") + } +} + +func BenchmarkLogIDStr(b *testing.B) { + id := restic.NewRandomID() + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + debug.Log("id: %v", id.Str()) + } +} + +func BenchmarkLogIDString(b *testing.B) { + id := restic.NewRandomID() + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + debug.Log("id: %v", id.String()) + } +}