#![feature(test)] extern crate test; extern crate classif; use test::black_box; use classif::*; #[bench] fn mean_value(bench: &mut test::Bencher) { let a = get_test_values(); let a = black_box(a); bench.iter(|| { let mean = stats::mean(&a); }); } #[bench] fn kurtosis_value(bench: &mut test::Bencher) { let a = get_test_values(); let a = black_box(a); bench.iter(|| { let mean = stats::kurtosis(&a); }); } #[bench] fn variance(bench: &mut test::Bencher) { let a = get_test_values(); let a = black_box(a); bench.iter(|| { let mean = stats::variance(&a); }); } #[bench] fn head_tail_raw(bench: &mut test::Bencher) { let a = get_test_values(); let mut a = black_box(a); bench.iter(|| { a.sort_by(|i, j| i.partial_cmp(j).unwrap()); let b = get_head_tail_breaks(&a); }); } #[bench] fn head_tail(bench: &mut test::Bencher) { let a = get_test_values(); let a = black_box(a); bench.iter(|| { let b = BoundsInfo::new(5, &a, Classification::HeadTail).unwrap(); }); } #[bench] fn jenks_breaks_sorted(bench: &mut test::Bencher) { let mut a = get_test_values(); a.sort_by(|i, j| i.partial_cmp(j).unwrap()); let a = black_box(a); bench.iter(|| { let b = get_jenks_breaks(&a, 5); }); } #[bench] fn jenks_breaks_raw(bench: &mut test::Bencher) { let a = get_test_values(); let mut a = black_box(a); bench.iter(|| { a.sort_by(|i, j| i.partial_cmp(j).unwrap()); let b = get_jenks_breaks(&a, 5); }); } #[bench] fn jenks_breaks(bench: &mut test::Bencher) { let a = get_test_values(); let a = black_box(a); bench.iter(|| { let b = BoundsInfo::new(5, &a, Classification::JenksNaturalBreaks).unwrap(); }); } fn get_test_values() -> [f64; 150] { [124.11953296196037, 103.92697087010856, 5.0622357064592896, 118.13809013028434, 95.22750103402414, 98.22403958076912, 4.444393054909623, 5.284051229789105, 27.49663799351298, 115.87267322653307, 44.471654327407165, 110.85189399783523, 104.11275847684895, 22.889698922180784, 84.1098800907737, 115.70620182326988, 40.13931812393115, 102.76100964817884, 134.40920388755774, 79.3317450345255, 59.245519050105436, 97.19669224510231, 19.969910977415513, 48.6986267325206, 5.165934913361192, 145.5750427848921, 43.18436616590445, 111.13191221254777, 103.77426520501247, 147.47620633517116, 18.193088180473353, 63.967292459098836, 77.97996568357644, 23.028916049882763, 94.42315402664828, 75.68040572966866, 67.65056713176767, 42.93476159287684, 140.66306787947354, 69.67215661335376, 52.77089969651371, 8.57768507869386, 75.87134387761282, 70.91818167490672, 89.75654257076619, 120.7616716324539, 85.35570846164444, 143.50158727433018, 11.372025937876023, 135.25988986503268, 137.04587743764435, 68.01196111488656, 121.25335488179616, 113.27114335651787, 72.65153613799845, 111.45123489876481, 78.94546311890548, 115.00007182667323, 139.51998134820184, 84.8024989074621, 14.065370121350485, 100.2219357568402, 125.86974757509077, 80.42714745093431, 79.18014822784704, 7.704464475158746, 18.071981022134327, 43.13480224046353, 45.651017655351104, 95.70719919135406, 106.39579851884123, 43.86197992690892, 69.9681848738559, 49.15249665049527, 22.683316601635596, 131.87938192861773, 42.43988577061869, 87.19992795732614, 115.36373636613784, 26.55399136866134, 53.854525533949165, 67.63192590166629, 103.74525707376472, 18.737424980412428, 85.74378646974968, 141.83485047254064, 90.21657860158919, 58.23906658609738, 5.833907646704156, 115.43549018930858, 63.50626471744455, 123.20712755640525, 117.50886097385894, 16.88747537329786, 22.611184208505563, 85.87374722846786, 73.10689468558701, 120.1927316653708, 66.65620341890923, 121.69108889954472, 144.18070028720138, 113.96037838849544, 85.82363422513735, 50.14759915455048, 88.60788510217486, 105.33007189922465, 120.35666069414617, 144.29812503661668, 107.30779975215874, 92.51676926989137, 60.493202563046225, 34.788698921112655, 17.700157636532875, 70.62329574517808, 147.5006501343314, 37.08704541897557, 44.2190330387979, 21.567337806030086, 38.07874405878746, 26.78293552546471, 70.89759619639838, 98.70377093443567, 58.33146608447851, 109.11563212528586, 68.40548963145368, 95.46529167541085, 55.01854128514142, 6.66121567710623, 133.83679352123215, 112.52009878968043, 144.19066197014348, 32.59342159678386, 78.90950386250051, 93.08502342632364, 143.63509253785557, 1.584320207632528, 50.78690328860014, 143.30327464291966, 145.98245316995263, 15.329020265262239, 149.2103889422507, 57.136606376433406, 77.49207673248564, 60.76571706479743, 146.69519831318323, 141.1883591719943, 48.759400187570236, 37.28632513634756, 80.57736459821275, 87.78774178945444] }