@@ -19,21 +19,25 @@ import TestsUtils
19
19
//
20
20
21
21
public let RandomValues = [
22
- BenchmarkInfo ( name: " RandomIntegersDef " , runFunction: run_RandomIntegersDef, tags: [ . api] ) ,
23
- BenchmarkInfo ( name: " RandomIntegersLCG " , runFunction: run_RandomIntegersLCG, tags: [ . api] ) ,
24
- BenchmarkInfo ( name: " RandomDoubleDef " , runFunction: run_RandomDoubleDef, tags: [ . api] ) ,
25
- BenchmarkInfo ( name: " RandomDoubleLCG " , runFunction: run_RandomDoubleLCG, tags: [ . api] ) ,
22
+ BenchmarkInfo ( name: " RandomIntegersDef " , runFunction: run_RandomIntegersDef,
23
+ tags: [ . api] , legacyFactor: 100 ) ,
24
+ BenchmarkInfo ( name: " RandomIntegersLCG " , runFunction: run_RandomIntegersLCG,
25
+ tags: [ . api] ) ,
26
+ BenchmarkInfo ( name: " RandomDoubleDef " , runFunction: run_RandomDoubleDef,
27
+ tags: [ . api] , legacyFactor: 100 ) ,
28
+ BenchmarkInfo ( name: " RandomDoubleLCG " , runFunction: run_RandomDoubleLCG,
29
+ tags: [ . api] , legacyFactor: 2 ) ,
26
30
]
27
31
28
32
/// A linear congruential PRNG.
29
33
struct LCRNG : RandomNumberGenerator {
30
34
private var state : UInt64
31
-
35
+
32
36
init ( seed: Int ) {
33
37
state = UInt64 ( truncatingIfNeeded: seed)
34
38
for _ in 0 ..< 10 { _ = next ( ) }
35
39
}
36
-
40
+
37
41
mutating func next( ) -> UInt64 {
38
42
state = 2862933555777941757 &* state &+ 3037000493
39
43
return state
@@ -44,7 +48,7 @@ struct LCRNG: RandomNumberGenerator {
44
48
public func run_RandomIntegersDef( _ N: Int ) {
45
49
for _ in 0 ..< N {
46
50
var x = 0
47
- for _ in 0 ..< 100_000 {
51
+ for _ in 0 ..< 1_000 {
48
52
x &+= Int . random ( in: 0 ... 10_000 )
49
53
}
50
54
blackHole ( x)
@@ -67,7 +71,7 @@ public func run_RandomIntegersLCG(_ N: Int) {
67
71
public func run_RandomDoubleDef( _ N: Int ) {
68
72
for _ in 0 ..< N {
69
73
var x = 0.0
70
- for _ in 0 ..< 100_000 {
74
+ for _ in 0 ..< 1_000 {
71
75
x += Double . random ( in: - 1000 ... 1000 )
72
76
}
73
77
blackHole ( x)
@@ -79,7 +83,7 @@ public func run_RandomDoubleLCG(_ N: Int) {
79
83
for _ in 0 ..< N {
80
84
var x = 0.0
81
85
var generator = LCRNG ( seed: 0 )
82
- for _ in 0 ..< 100_000 {
86
+ for _ in 0 ..< 50_000 {
83
87
x += Double . random ( in: - 1000 ... 1000 , using: & generator)
84
88
}
85
89
blackHole ( x)
0 commit comments