summaryrefslogtreecommitdiffstats
path: root/go/snowflake_bench_test.go
blob: ffad3998dcd8b2b19061d6fdb8e2b29d1c5f1cb0 (plain)
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
package snowflake

import "testing"

var benchmarkSnowflake = New()

func BenchmarkNew(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		New()
	}
}

func BenchmarkSnowflake_String(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchmarkSnowflake.String()
	}
}

func BenchmarkFromString(b *testing.B) {
	s := benchmarkSnowflake.String()
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		FromString(s)
	}
}

func BenchmarkSnowflake_Hex(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchmarkSnowflake.Hex()
	}
}

func BenchmarkFromHex(b *testing.B) {
	h := benchmarkSnowflake.Hex()
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		FromHex(h)
	}
}

func BenchmarkMarshalJSON(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchmarkSnowflake.MarshalJSON()
	}
}

func BenchmarkMarshalText(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchmarkSnowflake.MarshalText()
	}
}

func BenchmarkValue(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchmarkSnowflake.Value()
	}
}