generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrand_test.go
49 lines (45 loc) · 883 Bytes
/
rand_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
package u_test
import (
"fmt"
"math/rand"
"testing"
"moul.io/u"
)
func ExampleRandomLetters() {
rand.Seed(42)
fmt.Println(u.RandomLetters(8))
fmt.Println(u.RandomLetters(8))
fmt.Println(u.RandomLetters(8))
fmt.Println(u.RandomLetters(42))
// Output:
// HRukpTTu
// eZPtNeuv
// unhuksqV
// GzAdxlgghEjkMVeZJpmKqakmTRgKfBSWYjUNGkdmdt
}
func BenchmarkRandomLetters(b *testing.B) {
cases := []struct {
Name string
NumberOfLetters int
}{
{"1000", 100},
{"10000", 1000},
{"100000", 10000},
}
for _, bc := range cases {
b.Run(bc.Name, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
u.RandomLetters(bc.NumberOfLetters)
}
})
b.Run(bc.Name+"-parallel", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
u.RandomLetters(bc.NumberOfLetters)
}
})
})
}
}