forked from ericlagergren/decimal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_test.go
53 lines (48 loc) · 854 Bytes
/
scan_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
package decimal
import (
"math/rand"
"strconv"
"testing"
)
func randString() string {
const chars = "0123456789"
n := rand.Intn(5000)
if n == 0 {
n = 16
}
p := make([]byte, n)
for i := range p {
p[i] = chars[rand.Intn(len(chars))]
}
switch rand.Intn(3) {
case 0:
p = append(p, 'e', '+')
p = strconv.AppendInt(p, int64(rand.Intn(350)), 10)
case 1:
p = append(p, 'e', '-')
p = strconv.AppendInt(p, int64(rand.Intn(350)), 10)
case 2:
if lp := len(p); lp > 0 {
p[rand.Intn(lp)] = '.'
}
}
return string(p)
}
var benchInput = func() (a [4096]struct {
b Big
s string
}) {
for i := range a {
a[i].s = randString()
}
return a
}()
var globOk bool
func BenchmarkBig_SetString(b *testing.B) {
var ok bool
for i := 0; i < b.N; i++ {
m := &benchInput[i%len(benchInput)]
_, ok = m.b.SetString(m.s)
}
globOk = ok
}