X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=vendor%2Fgithub.com%2Flestrrat-go%2Fstrftime%2Fstrftime_bench_test.go;fp=vendor%2Fgithub.com%2Flestrrat-go%2Fstrftime%2Fstrftime_bench_test.go;h=643f370d17c2c71427740998f6e77af0ea311f7a;hp=0000000000000000000000000000000000000000;hb=bc213b29d91743bb9cb23c043f2856f47b34bb3e;hpb=5819de48d26c0812b18e97c52582985cfff9fe5d diff --git a/vendor/github.com/lestrrat-go/strftime/strftime_bench_test.go b/vendor/github.com/lestrrat-go/strftime/strftime_bench_test.go new file mode 100644 index 00000000..643f370d --- /dev/null +++ b/vendor/github.com/lestrrat-go/strftime/strftime_bench_test.go @@ -0,0 +1,80 @@ +// +build bench + +package strftime_test + +import ( + "bytes" + "log" + "net/http" + _ "net/http/pprof" + "testing" + "time" + + jehiah "github.com/jehiah/go-strftime" + fastly "github.com/fastly/go-utils/strftime" + lestrrat "github.com/lestrrat-go/strftime" + tebeka "github.com/tebeka/strftime" +) + +func init() { + go func() { + log.Println(http.ListenAndServe("localhost:8080", nil)) + }() +} + +const benchfmt = `%A %a %B %b %d %H %I %M %m %p %S %Y %y %Z` + +func BenchmarkTebeka(b *testing.B) { + var t time.Time + for i := 0; i < b.N; i++ { + tebeka.Format(benchfmt, t) + } +} + +func BenchmarkJehiah(b *testing.B) { + // Grr, uses byte slices, and does it faster, but with more allocs + var t time.Time + for i := 0; i < b.N; i++ { + jehiah.Format(benchfmt, t) + } +} + +func BenchmarkFastly(b *testing.B) { + var t time.Time + for i := 0; i < b.N; i++ { + fastly.Strftime(benchfmt, t) + } +} + +func BenchmarkLestrrat(b *testing.B) { + var t time.Time + for i := 0; i < b.N; i++ { + lestrrat.Format(benchfmt, t) + } +} + +func BenchmarkLestrratCachedString(b *testing.B) { + var t time.Time + f, _ := lestrrat.New(benchfmt) + // This benchmark does not take into effect the compilation time + for i := 0; i < b.N; i++ { + f.FormatString(t) + } +} + +func BenchmarkLestrratCachedWriter(b *testing.B) { + var t time.Time + f, _ := lestrrat.New(benchfmt) + var buf bytes.Buffer + b.ResetTimer() + + // This benchmark does not take into effect the compilation time + // nor the buffer reset time + for i := 0; i < b.N; i++ { + b.StopTimer() + buf.Reset() + b.StartTimer() + f.Format(&buf, t) + f.FormatString(t) + } +}