Small Rust library for calculating greatest common divisor crates.io/crates/gcd
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add benchmark

+52
+7
Cargo.toml
··· 8 8 repository = "https://github.com/frewsxcv/rust-gcd" 9 9 documentation = "https://docs.rs/gcd/" 10 10 categories = ["algorithms"] 11 + 12 + [dev-dependencies] 13 + criterion = "0.3" 14 + 15 + [[bench]] 16 + name = "gcd_benchmark" 17 + harness = false
+45
benches/gcd_benchmark.rs
··· 1 + extern crate criterion; 2 + extern crate gcd; 3 + 4 + use criterion::{black_box, criterion_group, criterion_main, Criterion}; 5 + use gcd::Gcd; 6 + 7 + fn criterion_benchmark(c: &mut Criterion) { 8 + c.bench_function("gcd u8", |b| b.iter(|| { 9 + black_box(0u8.gcd(0)); 10 + black_box(0u8.gcd(237)); 11 + black_box(237u8.gcd(0)); 12 + black_box(237u8.gcd(178)); 13 + })); 14 + 15 + c.bench_function("gcd u16", |b| b.iter(|| { 16 + black_box(0u16.gcd(0)); 17 + black_box(0u16.gcd(10)); 18 + black_box(237u16.gcd(0)); 19 + black_box(237u16.gcd(178)); 20 + })); 21 + 22 + c.bench_function("gcd u32", |b| b.iter(|| { 23 + black_box(0u32.gcd(0)); 24 + black_box(0u32.gcd(10)); 25 + black_box(237u32.gcd(0)); 26 + black_box(237u32.gcd(178)); 27 + })); 28 + 29 + c.bench_function("gcd u64", |b| b.iter(|| { 30 + black_box(0u64.gcd(0)); 31 + black_box(0u64.gcd(10)); 32 + black_box(237u64.gcd(0)); 33 + black_box(237u64.gcd(178)); 34 + })); 35 + 36 + c.bench_function("gcd u128", |b| b.iter(|| { 37 + black_box(0u128.gcd(0)); 38 + black_box(0u128.gcd(10)); 39 + black_box(237u128.gcd(0)); 40 + black_box(237u128.gcd(178)); 41 + })); 42 + } 43 + 44 + criterion_group!(benches, criterion_benchmark); 45 + criterion_main!(benches);