-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove redundant imports * Remove unused trait * Do not use deprecated "cargo-clippy" feature check Lints starting with "clippy::" are already recognized as being applicable to Clippy only. * Replace objects instead of recreating them `.clone_into()` avoids a whole object deallocation and reallocation. Flagged by recent Clippy. * Define generic parameter bound in one place only Flagged by recent Clippy. * Use Unix end-of-line convention for Rust source files * Add missing documentation comment
- Loading branch information
1 parent
9f1db4a
commit f1ea31a
Showing
34 changed files
with
1,380 additions
and
1,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#[macro_use] | ||
extern crate criterion_bencher_compat; | ||
|
||
use criterion_bencher_compat::Bencher; | ||
|
||
fn a(bench: &mut Bencher) { | ||
bench.iter(|| { | ||
(0..1000).fold(0, |x, y| x + y) | ||
}) | ||
} | ||
|
||
fn b(bench: &mut Bencher) { | ||
const N: usize = 1024; | ||
bench.iter(|| { | ||
vec![0u8; N] | ||
}); | ||
|
||
bench.bytes = N as u64; | ||
} | ||
|
||
benchmark_group!(benches, a, b); | ||
#[macro_use] | ||
extern crate criterion_bencher_compat; | ||
|
||
use criterion_bencher_compat::Bencher; | ||
|
||
fn a(bench: &mut Bencher) { | ||
bench.iter(|| { | ||
(0..1000).fold(0, |x, y| x + y) | ||
}) | ||
} | ||
|
||
fn b(bench: &mut Bencher) { | ||
const N: usize = 1024; | ||
bench.iter(|| { | ||
vec![0u8; N] | ||
}); | ||
|
||
bench.bytes = N as u64; | ||
} | ||
|
||
benchmark_group!(benches, a, b); | ||
benchmark_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
use criterion::{criterion_group, Criterion, SamplingMode}; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
fn sampling_mode_tests(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("sampling_mode"); | ||
|
||
group.sampling_mode(SamplingMode::Auto); | ||
group.bench_function("Auto", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(0))) | ||
}); | ||
|
||
group.sampling_mode(SamplingMode::Linear); | ||
group.bench_function("Linear", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(0))) | ||
}); | ||
|
||
group.sampling_mode(SamplingMode::Flat); | ||
group.bench_function("Flat", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(10))) | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, sampling_mode_tests,); | ||
use criterion::{criterion_group, Criterion, SamplingMode}; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
fn sampling_mode_tests(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("sampling_mode"); | ||
|
||
group.sampling_mode(SamplingMode::Auto); | ||
group.bench_function("Auto", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(0))) | ||
}); | ||
|
||
group.sampling_mode(SamplingMode::Linear); | ||
group.bench_function("Linear", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(0))) | ||
}); | ||
|
||
group.sampling_mode(SamplingMode::Flat); | ||
group.bench_function("Flat", |bencher| { | ||
bencher.iter(|| sleep(Duration::from_millis(10))) | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, sampling_mode_tests,); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
#![feature(custom_test_frameworks)] | ||
#![test_runner(criterion::runner)] | ||
|
||
use criterion::{Criterion, black_box}; | ||
use criterion_macro::criterion; | ||
|
||
fn fibonacci(n: u64) -> u64 { | ||
match n { | ||
0 | 1 => 1, | ||
n => fibonacci(n - 1) + fibonacci(n - 2), | ||
} | ||
} | ||
|
||
fn custom_criterion() -> Criterion { | ||
Criterion::default() | ||
.sample_size(50) | ||
} | ||
|
||
#[criterion] | ||
fn bench_simple(c: &mut Criterion) { | ||
c.bench_function("Fibonacci-Simple", |b| b.iter(|| fibonacci(black_box(10)))); | ||
} | ||
|
||
#[criterion(custom_criterion())] | ||
fn bench_custom(c: &mut Criterion) { | ||
c.bench_function("Fibonacci-Custom", |b| b.iter(|| fibonacci(black_box(20)))); | ||
#![feature(custom_test_frameworks)] | ||
#![test_runner(criterion::runner)] | ||
|
||
use criterion::{Criterion, black_box}; | ||
use criterion_macro::criterion; | ||
|
||
fn fibonacci(n: u64) -> u64 { | ||
match n { | ||
0 | 1 => 1, | ||
n => fibonacci(n - 1) + fibonacci(n - 2), | ||
} | ||
} | ||
|
||
fn custom_criterion() -> Criterion { | ||
Criterion::default() | ||
.sample_size(50) | ||
} | ||
|
||
#[criterion] | ||
fn bench_simple(c: &mut Criterion) { | ||
c.bench_function("Fibonacci-Simple", |b| b.iter(|| fibonacci(black_box(10)))); | ||
} | ||
|
||
#[criterion(custom_criterion())] | ||
fn bench_custom(c: &mut Criterion) { | ||
c.bench_function("Fibonacci-Custom", |b| b.iter(|| fibonacci(black_box(20)))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
use proc_macro2::{Ident, TokenTree}; | ||
use quote::quote_spanned; | ||
|
||
#[proc_macro_attribute] | ||
pub fn criterion(attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let attr = proc_macro2::TokenStream::from(attr); | ||
let item = proc_macro2::TokenStream::from(item); | ||
|
||
let span = proc_macro2::Span::call_site(); | ||
|
||
let init = if stream_length(attr.clone()) != 0 { | ||
attr | ||
} | ||
else { | ||
quote_spanned!(span=> criterion::Criterion::default()) | ||
}; | ||
|
||
let function_name = find_name(item.clone()); | ||
let wrapped_name = Ident::new(&format!("criterion_wrapped_{}", function_name.to_string()), span); | ||
|
||
let output = quote_spanned!(span=> | ||
#[test_case] | ||
pub fn #wrapped_name() { | ||
#item | ||
|
||
let mut c = #init.configure_from_args(); | ||
#function_name(&mut c); | ||
} | ||
); | ||
|
||
output.into() | ||
} | ||
|
||
fn stream_length(stream: proc_macro2::TokenStream) -> usize { | ||
stream.into_iter().count() | ||
} | ||
|
||
fn find_name(stream: proc_macro2::TokenStream) -> Ident { | ||
let mut iter = stream.into_iter(); | ||
while let Some(tok) = iter.next() { | ||
if let TokenTree::Ident(ident) = tok { | ||
if ident == "fn" { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if let Some(TokenTree::Ident(name)) = iter.next() { | ||
name | ||
} | ||
else { | ||
panic!("Unable to find function name") | ||
} | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
use proc_macro2::{Ident, TokenTree}; | ||
use quote::quote_spanned; | ||
|
||
#[proc_macro_attribute] | ||
pub fn criterion(attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let attr = proc_macro2::TokenStream::from(attr); | ||
let item = proc_macro2::TokenStream::from(item); | ||
|
||
let span = proc_macro2::Span::call_site(); | ||
|
||
let init = if stream_length(attr.clone()) != 0 { | ||
attr | ||
} | ||
else { | ||
quote_spanned!(span=> criterion::Criterion::default()) | ||
}; | ||
|
||
let function_name = find_name(item.clone()); | ||
let wrapped_name = Ident::new(&format!("criterion_wrapped_{}", function_name.to_string()), span); | ||
|
||
let output = quote_spanned!(span=> | ||
#[test_case] | ||
pub fn #wrapped_name() { | ||
#item | ||
|
||
let mut c = #init.configure_from_args(); | ||
#function_name(&mut c); | ||
} | ||
); | ||
|
||
output.into() | ||
} | ||
|
||
fn stream_length(stream: proc_macro2::TokenStream) -> usize { | ||
stream.into_iter().count() | ||
} | ||
|
||
fn find_name(stream: proc_macro2::TokenStream) -> Ident { | ||
let mut iter = stream.into_iter(); | ||
while let Some(tok) = iter.next() { | ||
if let TokenTree::Ident(ident) = tok { | ||
if ident == "fn" { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if let Some(TokenTree::Ident(name)) = iter.next() { | ||
name | ||
} | ||
else { | ||
panic!("Unable to find function name") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.