Improve ascii handling, improve performance

This commit is contained in:
2022-05-24 21:13:43 +02:00
parent 9f44196e6c
commit 17ea7bc60c
3 changed files with 26 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ use std::fs;
use criterion::{criterion_group, criterion_main, Criterion};
use u_norm::nfd;
use unic_normal::StrNormalForm;
use unicode_normalization::UnicodeNormalization;
const ASCII: &str = "all types of normalized";
@@ -10,8 +11,13 @@ const ASCII: &str = "all types of normalized";
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("ASCII");
group.bench_function("unf", |b| b.iter(|| nfd(ASCII).count()));
group.bench_function("unicode-normalization", |b| b.iter(|| ASCII.nfd().count()));
group.bench_function("u-norm", |b| b.iter(|| nfd(ASCII).count()));
group.bench_function("unicode-normalization", |b| {
b.iter(|| UnicodeNormalization::nfd(ASCII).count())
});
group.bench_function("unic-normal", |b| {
b.iter(|| StrNormalForm::nfd(ASCII).count())
});
group.finish();
@@ -19,8 +25,13 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Long");
group.bench_function("unf", |b| b.iter(|| nfd(&long).count()));
group.bench_function("unicode-normalization", |b| b.iter(|| long.nfd().count()));
group.bench_function("u-norm", |b| b.iter(|| nfd(&long).count()));
group.bench_function("unicode-normalization", |b| {
b.iter(|| UnicodeNormalization::nfd(long.as_str()).count())
});
group.bench_function("unic-normal", |b| {
b.iter(|| StrNormalForm::nfd(long.as_str()).count())
});
group.finish();
}