-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
96 lines (76 loc) · 1.68 KB
/
benchmark_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package monoflake_test
import (
"testing"
"time"
"github.com/mustafaturan/monoflake"
)
func BenchmarkNext(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0)
for n := 0; n < b.N; n++ {
_ = mf.Next()
}
}
func BenchmarkNextWithEpoch(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0, monoflake.WithEpoch(time.Now()))
for n := 0; n < b.N; n++ {
_ = mf.Next()
}
}
func BenchmarkNextCompare(b *testing.B) {
b.ReportAllocs()
mf, err := monoflake.New(0)
if err != nil {
b.Fatal(err)
}
var id1, id2 monoflake.ID
for n := 0; n < b.N; n++ {
id1, id2 = mf.Next(), mf.Next()
if id1 > id2 {
b.Fatalf("Next(): %d >= Next(): %d", id1, id2)
}
}
}
func BenchmarkNextBase62(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0)
for n := 0; n < b.N; n++ {
_ = mf.Next().String()
}
}
func BenchmarkNextBase62WithEpoch(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0, monoflake.WithEpoch(time.Now()))
for n := 0; n < b.N; n++ {
_ = mf.Next().String()
}
}
func BenchmarkNextBytes(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0)
for n := 0; n < b.N; n++ {
_ = mf.Next().Bytes()
}
}
func BenchmarkNextBytesWithEpoch(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0, monoflake.WithEpoch(time.Now()))
for n := 0; n < b.N; n++ {
_ = mf.Next().Bytes()
}
}
func BenchmarkNextBigEndianBytes(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0)
for n := 0; n < b.N; n++ {
_ = mf.Next().BigEndianBytes()
}
}
func BenchmarkNextBigEndianBytesWithEpoch(b *testing.B) {
b.ReportAllocs()
mf, _ := monoflake.New(0, monoflake.WithEpoch(time.Now()))
for n := 0; n < b.N; n++ {
_ = mf.Next().BigEndianBytes()
}
}