aboutsummaryrefslogtreecommitdiff
path: root/lib/std/hash/benchmark.zig
diff options
context:
space:
mode:
authorOminitay <37453713+Ominitay@users.noreply.github.com>2021-10-27 15:53:29 +0100
committerAndrew Kelley <andrew@ziglang.org>2021-10-27 16:07:48 -0400
commitc1a5ff34f3f68a2a0bc32828ab483328cd436fea (patch)
treebad85387a89da38890f72696ccfc0ae3c416ab0f /lib/std/hash/benchmark.zig
parent9024f27d8f5cb651e2260348ce0ee6fd67fc2c32 (diff)
downloadzig-c1a5ff34f3f68a2a0bc32828ab483328cd436fea.tar.gz
zig-c1a5ff34f3f68a2a0bc32828ab483328cd436fea.zip
std.rand: Refactor `Random` interface
These changes have been made to resolve issue #10037. The `Random` interface was implemented in such a way that causes significant slowdown when calling the `fill` function of the rng used. The `Random` interface is no longer stored in a field of the rng, and is instead returned by the child function `random()` of the rng. This avoids the performance issues caused by the interface.
Diffstat (limited to 'lib/std/hash/benchmark.zig')
-rw-r--r--lib/std/hash/benchmark.zig5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/std/hash/benchmark.zig b/lib/std/hash/benchmark.zig
index 9e6ec5b6bc..42102d644e 100644
--- a/lib/std/hash/benchmark.zig
+++ b/lib/std/hash/benchmark.zig
@@ -11,6 +11,7 @@ const MiB = 1024 * KiB;
const GiB = 1024 * MiB;
var prng = std.rand.DefaultPrng.init(0);
+const random = prng.random();
const Hash = struct {
ty: type,
@@ -88,7 +89,7 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize) !Result {
};
var block: [block_size]u8 = undefined;
- prng.random.bytes(block[0..]);
+ random.bytes(block[0..]);
var offset: usize = 0;
var timer = try Timer.start();
@@ -110,7 +111,7 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize) !Result {
pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize) !Result {
const key_count = bytes / key_size;
var block: [block_size]u8 = undefined;
- prng.random.bytes(block[0..]);
+ random.bytes(block[0..]);
var i: usize = 0;
var timer = try Timer.start();