Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 880e6b6

Browse files
stephenmichaelfdanmoseley
authored andcommitted
Add perf tests for Random.cs. (#19561)
* Add perf tests for Random.cs. * Add new line at end of file.
1 parent 70ae1fa commit 880e6b6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/System.Runtime.Extensions/tests/Performance/Perf.Random.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,34 @@ public void Next_int_int()
4949
rand.Next(100, 10000); rand.Next(100, 10000); rand.Next(100, 10000);
5050
}
5151
}
52+
53+
[Benchmark]
54+
public void NextBytes()
55+
{
56+
Random rand = new Random(123456);
57+
byte[] b1 = new byte[1000];
58+
foreach (var iteration in Benchmark.Iterations)
59+
using (iteration.StartMeasurement())
60+
for (int i = 0; i < 10000; i++)
61+
{
62+
rand.NextBytes(b1); rand.NextBytes(b1); rand.NextBytes(b1);
63+
rand.NextBytes(b1); rand.NextBytes(b1); rand.NextBytes(b1);
64+
rand.NextBytes(b1); rand.NextBytes(b1); rand.NextBytes(b1);
65+
}
66+
}
67+
68+
[Benchmark]
69+
public void NextDouble()
70+
{
71+
Random rand = new Random(123456);
72+
foreach (var iteration in Benchmark.Iterations)
73+
using (iteration.StartMeasurement())
74+
for (int i = 0; i < 40000; i++)
75+
{
76+
rand.NextDouble(); rand.NextDouble(); rand.NextDouble();
77+
rand.NextDouble(); rand.NextDouble(); rand.NextDouble();
78+
rand.NextDouble(); rand.NextDouble(); rand.NextDouble();
79+
}
80+
}
5281
}
5382
}

0 commit comments

Comments
 (0)