-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbase58bench_test.go
85 lines (69 loc) · 1.41 KB
/
base58bench_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
package base58_test
import (
"crypto/rand"
"github.com/akamensky/base58"
"log"
"testing"
)
func getRandomBytes(n int) []byte {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
log.Fatal("Something went wrong: ", err)
}
return b
}
func benchmarkEncode(n int, b *testing.B) {
b.StopTimer()
b.SetBytes(int64(n))
data := make([]([]byte), b.N, b.N)
for i := 0; i < b.N; i++ {
data[i] = getRandomBytes(n)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
base58.Encode(data[i])
}
}
func benchmarkDecode(n int, b *testing.B) {
b.StopTimer()
b.SetBytes(int64(n))
data := make([]string, b.N, b.N)
for i := 0; i < b.N; i++ {
data[i] = base58.Encode(getRandomBytes(n))
}
b.StartTimer()
for i := 0; i < b.N; i++ {
base58.Decode(data[i])
}
}
func BenchmarkEncode32(b *testing.B) {
benchmarkEncode(32, b)
}
func BenchmarkEncode64(b *testing.B) {
benchmarkEncode(64, b)
}
func BenchmarkEncode128(b *testing.B) {
benchmarkEncode(128, b)
}
func BenchmarkEncode256(b *testing.B) {
benchmarkEncode(256, b)
}
func BenchmarkEncode512(b *testing.B) {
benchmarkEncode(512, b)
}
func BenchmarkDecode32(b *testing.B) {
benchmarkDecode(32, b)
}
func BenchmarkDecode64(b *testing.B) {
benchmarkDecode(64, b)
}
func BenchmarkDecode128(b *testing.B) {
benchmarkDecode(128, b)
}
func BenchmarkDecode256(b *testing.B) {
benchmarkDecode(256, b)
}
func BenchmarkDecode512(b *testing.B) {
benchmarkDecode(512, b)
}