Add tests of data types

master
Trivernis 5 years ago
parent bd18e9f7cd
commit 4275d53531

10
Cargo.lock generated

@ -23,6 +23,7 @@ dependencies = [
"benchlib-rs",
"crossbeam-channel",
"crossbeam-utils",
"num-traits",
"num_cpus",
"rayon",
]
@ -132,6 +133,15 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.12.0"

@ -15,3 +15,4 @@ crossbeam-channel = "0.4.2"
benchlib-rs = "0.2.2"
crossbeam-utils = "0.7.2"
num_cpus = "1.0"
num-traits = "0.2.11"

@ -3,6 +3,7 @@
mod to_bench;
use benchlib::benching::Bencher;
use rayon::prelude::*;
pub fn main() {
let mut bencher = Bencher::new();
@ -11,12 +12,24 @@ pub fn main() {
.print_settings()
.bench("Dry Run", || {})
.bench("Multiply to 100", || to_bench::multiply_to(100))
.bench("Summation from 0u128 to 1000", || {
to_bench::summation_to(1000)
.bench("Summation from 0u32 to 10000", || {
to_bench::summation_to::<u32>(10000)
})
.bench("Summation from 0u64 to 10000", || {
to_bench::summation_to::<u64>(10000)
})
.compare()
.bench("Summation from 0u128 to 10000", || {
to_bench::summation_to::<u128>(10000)
})
.compare()
.bench("Parallel summation using rayon from 0u128 to 10000", || {
(0u128..10000).into_par_iter().sum::<u128>()
})
.compare()
.bench(
"Parallel summation with arc mutex from 0u128 to 1000",
|| to_bench::summation_using_mutex(1000),
"Parallel summation with arc mutex from 0u128 to 10000",
|| to_bench::summation_using_mutex(10000),
)
.compare()
.set_iterations(1000)

@ -1,6 +1,7 @@
use crossbeam_channel::unbounded;
use crossbeam_utils::sync::WaitGroup;
use num_cpus;
use num_traits::{PrimInt, Unsigned};
use rayon::prelude::*;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
@ -13,10 +14,12 @@ pub fn start_stop_thread() {
handle.join().unwrap();
}
pub fn summation_to(end: u128) -> u128 {
let mut res = 0u128;
for i in 0u128..end {
res += i;
pub fn summation_to<T: PrimInt + Unsigned>(end: T) -> T {
let mut res: T = T::zero();
let mut i = T::zero();
while i < end {
res = res + i;
i = i + T::one();
}
res
}

Loading…
Cancel
Save