Add first benchmark
This commit is contained in:
parent
399eed7646
commit
57099e2a0e
2 changed files with 34 additions and 0 deletions
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "nvector"
|
||||
version = "0.1.0"
|
||||
authors = ["Armin Becher <armin.becher@methodpark.de>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
criterion = "0.3.1"
|
||||
|
||||
[[bench]]
|
||||
name = "two_dim_array"
|
||||
harness = false
|
20
benches/two_dim_array.rs
Normal file
20
benches/two_dim_array.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
fn init(x: usize, y: usize) -> Vec<Vec<u32>> {
|
||||
vec![vec![42; x]; y]
|
||||
}
|
||||
|
||||
fn init_flat(x: usize, y: usize) -> Vec<u32> {
|
||||
vec![42; x * y]
|
||||
}
|
||||
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("Init 20x20", |b| b.iter(|| init(black_box(20), black_box(20))));
|
||||
c.bench_function("Init flat 20x20", |b| b.iter(|| init_flat(black_box(20), black_box(20))));
|
||||
c.bench_function("Init 2000x2000", |b| b.iter(|| init(black_box(2000), black_box(2000))));
|
||||
c.bench_function("Init flat 2000x2000", |b| b.iter(|| init_flat(black_box(2000), black_box(2000))));
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
Loading…
Reference in a new issue