Created
May 16, 2018 20:48
-
-
Save tommyettinger/3a98476f111d2d0ea4e72cbcba0b504e to your computer and use it in GitHub Desktop.
Linnorm benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Linnorm { | |
private static long state = 0L; | |
private static long random() | |
{ | |
long z = (state = state * 0x41C64E6DL + 1L); | |
z = (z ^ z >>> 28) * 0xAEF17502108EF2D9L; | |
return z ^ z >>> 30; | |
} | |
public static void main(String[] args) { | |
long out = 0L; | |
for (int i = 0; i < 1000000000; i++) { | |
out += random(); // Java is inlining this; manually inlining slows it down | |
} | |
final long startTime = System.nanoTime(); | |
for (int a = 0; a < 20; a++) { | |
for (int i = 0; i < 1000000000; i++) { | |
out += random(); | |
} | |
} | |
System.out.println(System.nanoTime() - startTime); | |
System.out.println(out); // may be negative, Rust uses an unsigned type so convert before checking equality | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate time; | |
use std::num::Wrapping; | |
fn main() { | |
let mut state : Wrapping<u64> = Wrapping(0u64); | |
let mut z: Wrapping<u64>; | |
let mut out: Wrapping<u64> = Wrapping(0u64); | |
let t = time::precise_time_ns(); | |
for _ in 0..1_000_000_000 { | |
state = state * Wrapping(0x41C64E6Du64) + Wrapping(1u64); // inlined manually, perhaps someone can make this a function | |
z = state; | |
z = (z ^ z >> 28) * Wrapping(0xAEF17502108EF2D9u64); | |
out += z ^ z >> 30 | |
} | |
for _ in 0..20 { | |
for _ in 0..1_000_000_000 { | |
state = state * Wrapping(0x41C64E6Du64) + Wrapping(1u64); | |
z = state; | |
z = (z ^ z >> 28) * Wrapping(0xAEF17502108EF2D9u64); | |
out += z ^ z >> 30 | |
} | |
} | |
println!("{}", time::precise_time_ns() - t); | |
println!("{}", out.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment