ByteNgramReader is almost as fast as from_slice.

This commit is contained in:
2018-01-09 18:21:08 +01:00
parent 92fa9401cf
commit 8fd169ed3f
2 changed files with 80 additions and 37 deletions

View File

@@ -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);