Created
July 11, 2017 15:57
-
-
Save CensoredUsername/36f3bb1ffce99166fd871ccfd368da4b to your computer and use it in GitHub Desktop.
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
$ cargo bench | |
Finished release [optimized] target(s) in 0.0 secs | |
Running target\release\deps\benching-22b624a5099107eb.exe | |
running 2 tests | |
test tests::loop_notrash ... bench: 1,053,106 ns/iter (+/- 162,958) | |
test tests::loop_trash ... bench: 1,458,335 ns/iter (+/- 149,239) | |
test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured |
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
rust_iter_notrash: | |
incq %rcx | |
xorl %r8d, %r8d | |
xorl %r9d, %r9d | |
.LBB0_1: | |
movq %r9, %rax | |
leaq -2(%rax,%r8,2), %r9 | |
movq %r8, %rdx | |
.LBB0_2: | |
cmpq %rcx, %rdx | |
jge .LBB0_4 | |
leaq 1(%rdx), %r8 | |
addq $2, %r9 | |
testb $32, %dl | |
movq %r8, %rdx | |
jne .LBB0_2 | |
jmp .LBB0_1 | |
.LBB0_4: | |
retq | |
rust_iter_trash: | |
incq %rcx | |
xorl %r8d, %r8d | |
xorl %r9d, %r9d | |
.LBB1_1: | |
movq %r9, %rax | |
leaq -2(%rax,%r8,2), %r9 | |
movq %r8, %rdx | |
.LBB1_2: | |
cmpq %rcx, %rdx | |
jge .LBB1_4 | |
leaq 1(%rdx), %r8 | |
addq $2, %r9 | |
testb $1, %dl | |
movq %r8, %rdx | |
jne .LBB1_2 | |
jmp .LBB1_1 | |
.LBB1_4: | |
retq | |
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
extern crate test; | |
type T = isize; | |
#[no_mangle] | |
pub fn rust_iter_notrash(high: T) -> T { | |
(0..high +1) | |
.filter(|x| (x & 0x20) == 0) | |
.map(|x| x * 2) | |
.sum() | |
} | |
#[no_mangle] | |
pub fn rust_iter_trash(high: T) -> T { | |
(0..high +1) | |
.filter(|x| x % 2 == 0) | |
.map(|x| x * 2) | |
.sum() | |
} | |
#[cfg(test)] | |
mod tests { | |
use test; | |
#[bench] | |
fn loop_notrash(b: &mut test::Bencher) { | |
b.iter(||{ | |
assert!(::rust_iter_notrash(1_000_000) != 0); | |
}); | |
} | |
#[bench] | |
fn loop_trash(b: &mut test::Bencher) { | |
b.iter(||{ | |
assert!(::rust_iter_trash(1_000_000) != 0); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment