1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#![feature(test)] extern crate test; extern crate frunk; use frunk::semigroup::*; use test::Bencher; #[bench] fn combine_i32(b: &mut Bencher) { let x: i32 = 10; let y: i32 = 50; b.iter(|| x.combine(&y)) } #[bench] fn std_add_i32(b: &mut Bencher) { let x: i32 = 10; let y: i32 = 50; b.iter(|| x + y) } #[bench] fn combine_option_string(b: &mut Bencher) { let x: Option<String> = Some("hello".to_owned()); let y: Option<String> = Some(" world".to_owned()); b.iter(|| x.combine(&y)) } #[bench] fn std_add_option_string(b: &mut Bencher) { let x: Option<String> = Some("hello".to_owned()); let y: Option<String> = Some(" world".to_owned()); b.iter(|| { // cloning is required otherwise we get `cannot move out of captured outer variable in an `FnMut` closure` errors let a = x.clone(); let b = y.clone(); a.and_then(|first| { b.map(|second| first + &second ) }) }) }