-
Notifications
You must be signed in to change notification settings - Fork 0
/
strftime_bench_test.go
77 lines (65 loc) · 1.44 KB
/
strftime_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//go:build bench
package strftime_test
import (
"log"
"net/http"
_ "net/http/pprof"
"testing"
"time"
magicaltux "github.com/KarpelesLab/strftime"
cactus "github.com/cactus/gostrftime"
fastly "github.com/fastly/go-utils/strftime"
jehiah "github.com/jehiah/go-strftime"
leekchan "github.com/leekchan/timeutil"
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 BenchmarkCactus(b *testing.B) {
var t time.Time
for i := 0; i < b.N; i++ {
cactus.Format(benchfmt, t)
}
}
func BenchmarkLeekchan(b *testing.B) {
var t time.Time
for i := 0; i < b.N; i++ {
leekchan.Strftime(&t, benchfmt)
}
}
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 BenchmarkKarpelesLab(b *testing.B) {
var t time.Time
for i := 0; i < b.N; i++ {
magicaltux.EnFormat(benchfmt, t)
}
}