Skip to content

Commit 26cc495

Browse files
authored
feat:add scalable_rand test (polarismesh#207)
* feat:add scalable_rand test * Add empty line
1 parent da0176e commit 26cc495

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Diff for: common/srand/scalable_rand_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making polaris-go available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package srand
19+
20+
import (
21+
"math/rand"
22+
"testing"
23+
)
24+
25+
func BenchmarkSingleCore(b *testing.B) {
26+
27+
b.Run("scalable_rand-Intn()", func(b *testing.B) {
28+
for i := 0; i < b.N; i++ {
29+
_ = Intn(1000)
30+
}
31+
})
32+
33+
b.Run("math/rand-Intn()", func(b *testing.B) {
34+
for i := 0; i < b.N; i++ {
35+
_ = rand.Intn(1000)
36+
}
37+
})
38+
39+
}
40+
41+
func BenchmarkMultipleCore(b *testing.B) {
42+
43+
b.Run("scalable_rand-Intn()", func(b *testing.B) {
44+
b.RunParallel(func(pb *testing.PB) {
45+
for pb.Next() {
46+
_ = Intn(1000)
47+
}
48+
})
49+
})
50+
51+
b.Run("math/rand-Intn()", func(b *testing.B) {
52+
b.RunParallel(func(pb *testing.PB) {
53+
for pb.Next() {
54+
_ = rand.Intn(1000)
55+
}
56+
})
57+
})
58+
59+
}

0 commit comments

Comments
 (0)