diff options
author | Samson <16504129+sagudev@users.noreply.github.com> | 2024-09-30 12:56:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-30 10:56:18 +0000 |
commit | 1ddfde96ce15687dea84be4e55cee3d381177804 (patch) | |
tree | 58303deacfb42d61819aa48eb03b41546356697c /components | |
parent | 58f34ad7a3db8c633871d568bfcef8b094217e3e (diff) | |
download | servo-1ddfde96ce15687dea84be4e55cee3d381177804.tar.gz servo-1ddfde96ce15687dea84be4e55cee3d381177804.zip |
Add a benchmark for for `unmultiply_inplace` in `pixels` (#33584)
* bench unmultiply_inplace
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* create data in one line
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* number_of_pixels
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Diffstat (limited to 'components')
-rw-r--r-- | components/pixels/Cargo.toml | 8 | ||||
-rw-r--r-- | components/pixels/benches.rs | 30 |
2 files changed, 38 insertions, 0 deletions
diff --git a/components/pixels/Cargo.toml b/components/pixels/Cargo.toml index 595c4861008..4d5b16ab9a4 100644 --- a/components/pixels/Cargo.toml +++ b/components/pixels/Cargo.toml @@ -20,3 +20,11 @@ malloc_size_of_derive = { workspace = true } log = { workspace = true } serde = { workspace = true, features = ["derive"] } webrender_api = { workspace = true } + +[dev-dependencies] +criterion = { version = "0.5", features = ["html_reports"] } + +[[bench]] +name = "benches" +path = "benches.rs" +harness = false diff --git a/components/pixels/benches.rs b/components/pixels/benches.rs new file mode 100644 index 00000000000..50002851d45 --- /dev/null +++ b/components/pixels/benches.rs @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use criterion::*; + +fn create_data(number_of_pixels: usize) -> Vec<u8> { + (0..=number_of_pixels) + .map(|i| { + let i = (i % 255) as u8; + [i, i, i, i] + }) + .flatten() + .collect() +} + +fn bench(c: &mut Criterion) { + let data = create_data(1_000_000); + + c.bench_function("unmultiply_inplace", move |b| { + b.iter_batched( + || data.clone(), + |mut data| pixels::unmultiply_inplace(&mut data), + BatchSize::SmallInput, + ) + }); +} + +criterion_group!(benches, bench); +criterion_main!(benches); |