Last active
November 19, 2019 04:08
-
-
Save hadronzoo/2474e64b91b733ca1fe8169ab0a0cdfd to your computer and use it in GitHub Desktop.
SMT microbenchmark in Rust
This file contains hidden or 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
# Late 2013 MacBook Pro | |
# 2.3 GHz Quad-Core Intel Core i7 | |
smt_8 time: [788.66 us 791.31 us 794.22 us] | |
Found 9 outliers among 100 measurements (9.00%) | |
5 (5.00%) high mild | |
4 (4.00%) high severe |
This file contains hidden or 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
[package] | |
name = "triggering" | |
version = "0.1.0" | |
authors = ["Joshua Griffith <[email protected]>"] | |
edition = "2018" | |
[dependencies] | |
rand = "0.7" | |
[dev-dependencies] | |
criterion = "0.3" | |
[[bench]] | |
name = "smt_benchmark" | |
harness = false |
This file contains hidden or 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
pub fn smt_8(times: &[u32]) -> Vec<(&[u32], u32)> { | |
const WINDOW_SIZE: usize = 8; | |
times | |
.windows(WINDOW_SIZE) | |
.map(|x| (x, x[WINDOW_SIZE - 1] - x[0])) | |
.filter(|&x| x.1 < 1_000) | |
.collect() | |
} |
This file contains hidden or 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
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | |
use rand::{thread_rng, Rng}; | |
use std::iter::successors; | |
use triggering::smt_8; | |
pub fn criterion_benchmark(c: &mut Criterion) { | |
const TIMES_LENGTH: usize = 1_000_000; | |
let mut rng = thread_rng(); | |
let numbers: Vec<u32> = successors(Some(0), |&x| Some(x + rng.gen_range(0, 1_000))) | |
.take(TIMES_LENGTH) | |
.collect(); | |
c.bench_function("smt_8", |b| b.iter(|| smt_8(black_box(&numbers)))); | |
} | |
criterion_group!(benches, criterion_benchmark); | |
criterion_main!(benches); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment