-
-
Save LukasKalbertodt/7eaf9399d3a3220dae16ef64a46f0ba9 to your computer and use it in GitHub Desktop.
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; | |
use test::Bencher; | |
#[bench] | |
fn array_stack(b: &mut Bencher) { | |
const LENGTH: usize = 10_000; | |
b.iter(|| { | |
let mut a: [i32; LENGTH] = [0; LENGTH]; | |
for j in 0..LENGTH { | |
for i in 0..LENGTH { | |
a[i] = j as i32; | |
} | |
} | |
a | |
}); | |
} | |
#[bench] | |
fn array_heap(b: &mut Bencher) { | |
const LENGTH: usize = 10_000; | |
b.iter(|| { | |
let mut a: Box<[i32; LENGTH]> = Box::new([0; LENGTH]); | |
for j in 0..LENGTH { | |
for i in 0..LENGTH { | |
a[i] = j as i32; | |
} | |
} | |
a | |
}); | |
} | |
#[bench] | |
fn vec_heap(b: &mut Bencher) { | |
const LENGTH: usize = 10_000; | |
b.iter(|| { | |
let mut a: Vec<i32> = vec![0; LENGTH]; | |
for j in 0..LENGTH { | |
for i in 0..LENGTH { | |
a[i] = j as i32; | |
} | |
} | |
a | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment