Add setup stage to benchmarks

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/14/head
trivernis 3 years ago
parent 89d9dc557c
commit 48a3838cb0
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -27,8 +27,13 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Run benchmark
run: cargo bench
run: cargo bench ${{steps.extract_branch.outputs.branch}}
- name: upload artifact
uses: actions/upload-artifact@v2

@ -8,6 +8,9 @@ license = "Apache-2.0"
repository = "https://github.com/Trivernis/rmp-ipc"
description = "IPC using Rust MessagePack (rmp)"
[lib]
bench=false
[[bench]]
name = "serialization_benchmark"
harness = false

@ -1,6 +1,6 @@
use criterion::Criterion;
use criterion::{black_box, BenchmarkId, Throughput};
use criterion::{criterion_group, criterion_main};
use criterion::{BatchSize, Criterion};
use std::io::Cursor;
use rmp_ipc::event::Event;
@ -19,13 +19,19 @@ fn event_deserialization(c: &mut Criterion) {
let runtime = Runtime::new().unwrap();
let mut group = c.benchmark_group("event_deserialization");
for size in (0..32).map(|i| i * 1024) {
group.throughput(Throughput::Bytes(size));
for size in (0..10)
.step_by(2)
.map(|i| 1024 * 2u32.pow(i as u32) as usize)
{
group.throughput(Throughput::Bytes(size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| {
b.to_async(&runtime).iter(|| async {
let mut reader = black_box(create_event_bytes_reader(size as usize));
Event::from_async_read(&mut reader).await.unwrap()
})
b.to_async(&runtime).iter_batched(
|| black_box(create_event_bytes_reader(size)),
|mut reader| async move {
Event::from_async_read(&mut reader).await.unwrap();
},
BatchSize::LargeInput,
)
});
}
group.finish()

@ -1,4 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use criterion::{
black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput,
};
use rmp_ipc::event::Event;
pub const EVENT_NAME: &str = "bench_event";
@ -10,10 +12,17 @@ fn create_event(data_size: usize) -> Event {
fn event_serialization(c: &mut Criterion) {
let mut group = c.benchmark_group("event_serialization");
for size in (0..32).map(|i| i * 1024) {
group.throughput(Throughput::Bytes(size));
for size in (0..10)
.step_by(2)
.map(|i| 1024 * 2u32.pow(i as u32) as usize)
{
group.throughput(Throughput::Bytes(size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| {
b.iter(|| black_box(create_event(size as usize)).into_bytes().unwrap())
b.iter_batched(
|| black_box(create_event(size)),
|event| event.into_bytes().unwrap(),
BatchSize::LargeInput,
)
});
}
group.finish();

Loading…
Cancel
Save