forked from unicode-org/icu4x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benches, implement new constructor APIs with docs, clippy
- Loading branch information
Showing
7 changed files
with
100 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
extern crate alloc; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use icu_provider::datagen::IterableDataProvider; | ||
use icu_provider::hello_world::*; | ||
use icu_provider::prelude::*; | ||
use icu_provider_blob::BlobDataProvider; | ||
|
||
const BLOB_V1: &[u8] = include_bytes!("../tests/data/v1.postcard"); | ||
const BLOB_V2: &[u8] = include_bytes!("../tests/data/v2.postcard"); | ||
|
||
fn blob_version_bench(c: &mut Criterion) { | ||
c.bench_function("provider/construct/v1", |b| { | ||
b.iter(|| BlobDataProvider::try_new_from_static_blob(black_box(BLOB_V1)).unwrap()); | ||
}); | ||
c.bench_function("provider/construct/v2", |b| { | ||
b.iter(|| BlobDataProvider::try_new_from_static_blob(black_box(BLOB_V1)).unwrap()); | ||
}); | ||
|
||
let hello_world_provider = HelloWorldProvider; | ||
let locales = hello_world_provider.supported_locales().unwrap(); | ||
|
||
c.bench_function("provider/read/v1", |b| { | ||
let provider = BlobDataProvider::try_new_from_static_blob(black_box(BLOB_V1)).unwrap(); | ||
b.iter(|| { | ||
for locale in black_box(&locales).iter() { | ||
let _: DataResponse<HelloWorldV1Marker> = black_box(&provider) | ||
.as_deserializing() | ||
.load(DataRequest { | ||
locale, | ||
metadata: Default::default(), | ||
}) | ||
.unwrap(); | ||
} | ||
}); | ||
}); | ||
c.bench_function("provider/read/v2", |b| { | ||
let provider = BlobDataProvider::try_new_from_static_blob(black_box(BLOB_V2)).unwrap(); | ||
b.iter(|| { | ||
for locale in black_box(&locales).iter() { | ||
let _: DataResponse<HelloWorldV1Marker> = black_box(&provider) | ||
.as_deserializing() | ||
.load(DataRequest { | ||
locale, | ||
metadata: Default::default(), | ||
}) | ||
.unwrap(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, blob_version_bench,); | ||
criterion_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
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