ByteNgramReader is almost as fast as from_slice.
This commit is contained in:
@@ -3,19 +3,17 @@ extern crate criterion;
|
||||
|
||||
extern crate byte_ngram;
|
||||
|
||||
use criterion::{Criterion, Fun};
|
||||
use criterion::Criterion;
|
||||
|
||||
use byte_ngram::{ByteNgramReader, from_slice};
|
||||
use byte_ngram::*;
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let data = String::from("Blackmail is such an ugly word. I prefer extortion. The 'x' makes it sound cool.");
|
||||
let data = String::from(
|
||||
"Blackmail is such an ugly word. I prefer extortion. The 'x' makes it sound cool.",
|
||||
);
|
||||
|
||||
let fn_from_slice = Fun::new("from_slice", |b, i: &String| b.iter(|| for _ in from_slice(i.as_bytes()) {}));
|
||||
let fn_from_reader = Fun::new("ByteNgramReader", |b, i: &String| b.iter(|| for _ in ByteNgramReader::new(i.as_bytes()) {}));
|
||||
|
||||
let functions = vec![fn_from_slice, fn_from_reader];
|
||||
|
||||
c.bench_functions("Read", functions, &data);
|
||||
c.bench_function("from_slice", |b| b.iter(|| for _ in from_slice(data.as_bytes()) {}));
|
||||
c.bench_function("ByteNgramReader", |b| b.iter(|| for _ in ByteNgramReader::new(data.as_bytes()) {}));
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
||||
Reference in New Issue
Block a user