-
Notifications
You must be signed in to change notification settings - Fork 6
/
format_test.go
52 lines (47 loc) · 935 Bytes
/
format_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
package factorlog
import (
"testing"
)
// allDigits converts an integer d to its ascii presentation,
// no matter how big the number is
// i is the deinstation index in buf
func allDigits(buf *[]byte, i, d int) int {
j := len(*buf)
// reverse order
for {
j--
(*buf)[j] = digits[d%10]
d /= 10
if d == 0 {
break
}
}
return copy((*buf)[i:], (*buf)[j:])
}
func BenchmarkLangAllDigits(b *testing.B) {
var buf []byte
tmp := make([]byte, 64)
for x := 0; x < b.N; x++ {
allDigits(&tmp, 0, 3456)
buf = append(buf, tmp...)
buf = []byte{}
}
}
func BenchmarkLangItoa(b *testing.B) {
var buf []byte
tmp := make([]byte, 64)
for x := 0; x < b.N; x++ {
Itoa(&tmp, 0, 3456)
buf = append(buf, tmp...)
buf = []byte{}
}
}
func BenchmarkLangNDigits(b *testing.B) {
var buf []byte
tmp := make([]byte, 64)
for x := 0; x < b.N; x++ {
NDigits(&tmp, 4, 0, 3456)
buf = append(buf, tmp...)
buf = []byte{}
}
}