Skip to content

[benchmark] Breadcrumbs: swap PRNG implementations #24367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions benchmark/single-source/Breadcrumbs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@ extension String {
}
}

let seed = 0x12345678

/// A linear congruential PRNG.
struct LCRNG: RandomNumberGenerator {
private var state: UInt64

init(seed: Int) {
state = UInt64(truncatingIfNeeded: seed)
for _ in 0..<10 { _ = next() }
}

mutating func next() -> UInt64 {
state = 2862933555777941757 &* state &+ 3037000493
return state
}
}

extension Collection {
/// Returns a randomly ordered array of random non-overlapping index ranges
/// that cover this collection entirely.
Expand Down Expand Up @@ -254,7 +237,7 @@ class UTF16ToIdx: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
let range = 0 ..< inputString.utf16.count
inputOffsets = Array(range.shuffled(using: &rng).prefix(count))
}
Expand Down Expand Up @@ -286,7 +269,7 @@ class IdxToUTF16: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
}

Expand Down Expand Up @@ -318,7 +301,7 @@ class UTF16ToIdxRange: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
inputOffsets = (
0 ..< inputString.utf16.count
).randomIndexRanges(count: count, using: &rng)
Expand Down Expand Up @@ -352,7 +335,7 @@ class IdxToUTF16Range: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
inputIndices = self.inputString.randomIndexRanges(count: count, using: &rng)
}

Expand Down Expand Up @@ -384,7 +367,7 @@ class CopyUTF16CodeUnits: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
inputIndices = (
0 ..< inputString.utf16.count
).randomIndexRanges(count: count, using: &rng)
Expand Down Expand Up @@ -425,7 +408,7 @@ class MutatedUTF16ToIdx: BenchmarkBase {

override func setUp() {
super.setUp()
var generator = LCRNG(seed: seed)
var generator = SplitMix64(seed: 42)
let range = 0 ..< inputString.utf16.count
inputOffsets = Array(range.shuffled(using: &generator).prefix(count))
}
Expand Down Expand Up @@ -469,7 +452,7 @@ class MutatedIdxToUTF16: BenchmarkBase {

override func setUp() {
super.setUp()
var rng = LCRNG(seed: seed)
var rng = SplitMix64(seed: 42)
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
}

Expand Down