Created
June 10, 2018 10:01
-
-
Save natsukium/6864216022eaf61983a38d696bccf166 to your computer and use it in GitHub Desktop.
Benchmark with tarai function for Rust
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
#![feature(test)] | |
extern crate test; | |
pub fn tarai(x: i32, y: i32, z: i32) -> i32 { | |
if x <= y { | |
y | |
} else { | |
tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)) | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use test::Bencher; | |
#[test] | |
fn it_works() { | |
assert_eq!(10, tarai(4, 10, 2)); | |
} | |
#[bench] | |
fn bench_tarai(b: &mut Bencher) { | |
b.iter(|| { | |
let x = test::black_box(13); | |
let y = test::black_box(5); | |
let z = test::black_box(0); | |
tarai(x, y, z) | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment