Add bitshift benchmarking

master
Trivernis 5 years ago
parent 7f0bf4b81b
commit db978eb135

4
Cargo.lock generated

@ -8,9 +8,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "benchlib-rs"
version = "0.2.2"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eec9a8d80e5bb03637e22ea0900b8ac12c3b9e21215dfda88347b03f056d5d7"
checksum = "e2b157249b658c600bea79e0ab5366561edf01f6e0dd0ba0075f0ad3945c2420"
dependencies = [
"rayon",
"termion",

@ -12,7 +12,7 @@ opt-level = 1
[dependencies]
rayon = "1.3.0"
crossbeam-channel = "0.4.2"
benchlib-rs = "0.2.2"
benchlib-rs = "0.3.1"
crossbeam-utils = "0.7.2"
num_cpus = "1.0"
num-traits = "0.2.11"

@ -2,15 +2,27 @@
mod to_bench;
use crate::to_bench::{bitshift_byte, max_f32_multiplication, max_u64_multiplications};
use benchlib::benching::Bencher;
use rayon::prelude::*;
pub fn noop() {}
pub fn main() {
let mut bencher = Bencher::new();
bencher
.set_iterations(10000)
.print_settings()
.bench("Dry Run", || {})
.bench("Empty closure", || {})
.bench("Empty fn", noop)
.bench("Empty loop to 1000", || for _ in 0..1000 {})
.bench("u64::MAX x u64::MAX 1000 times", || {
max_u64_multiplications(1000)
})
.bench("f32::MAX x f32::MAX 1000 times", || {
max_f32_multiplication(1000)
})
.bench("Bitshift u16 1 byte 1000 times", || bitshift_byte(1000))
.bench("Multiply to 100", || to_bench::multiply_to(100))
.bench("Summation from 0u32 to 10000", || {
to_bench::summation_to::<u32>(10000)

@ -3,9 +3,11 @@ use crossbeam_utils::sync::WaitGroup;
use num_cpus;
use num_traits::{PrimInt, Unsigned};
use rayon::prelude::*;
use std::f32;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
use std::thread;
use std::u64;
pub fn start_stop_thread() {
let handle = thread::spawn(|| {
@ -123,3 +125,31 @@ pub fn start_and_wait_for_num_cpu_threads() {
}
wg.wait();
}
pub fn max_f32_multiplication(times: usize) -> f64 {
let mut result = 0f64;
for _ in 0..times {
result = f32::MAX as f64 * f32::MAX as f64;
}
result
}
pub fn max_u64_multiplications(times: usize) -> u128 {
let mut result = 0u128;
for _ in 0..times {
result = u64::MAX as u128 * u64::MAX as u128
}
result
}
pub fn bitshift_byte(times: usize) -> u16 {
let mut result = 0u16;
for _ in 0..(times / 2) {
result = result << 8;
result = result >> 8;
}
result
}

Loading…
Cancel
Save