Last active
April 27, 2021 09:47
-
-
Save niklasad1/fefff366ed19b692cc964a17a13fbc19 to your computer and use it in GitHub Desktop.
Bench jsonrpc types v1 vs v2
This file contains hidden or 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
pub mod batch_input; | |
use jsonrpsee_types::v2::{response::*, error::*}; | |
criterion_group!(benches, v); | |
criterion_main!(benches); | |
enum OutputV2 { | |
Single(JsonRpcResponse<'static, Value>), | |
Notif(JsonRpcNotifResponse<Value>), | |
Batch(Vec<JsonRpcResponse<'static, Value>>), | |
Error(JsonRpcErrorAlloc), | |
} | |
fn types_v1(s: &'static str) -> jsonrpc_core::types::Response { | |
serde_json::from_str(s).unwrap() | |
} | |
fn types_v2(raw: &'static str) -> OutputV2 { | |
if let Ok(single) = serde_json::from_str::<JsonRpcResponse<_>>(&raw) { | |
OutputV2::Single(single) | |
} else if let Ok(n) = serde_json::from_str::<JsonRpcNotifResponse<_>>(&raw) { | |
OutputV2::Notif(n) | |
} else if let Ok(batch) = serde_json::from_str::<Vec<JsonRpcResponse<_>>>(&raw) { | |
OutputV2::Batch(batch) | |
} else if let Ok(err) = serde_json::from_str::<JsonRpcErrorAlloc>(&raw) { | |
OutputV2::Error(err) | |
} else { | |
panic!("unreachable") | |
} | |
} | |
fn v(c: &mut Criterion) { | |
c.bench_function("v1 batch deser small", |b| b.iter(|| types_v1(batch_input::INPUT_10))); | |
c.bench_function("v1 batch deser mid", |b| b.iter(|| types_v1(batch_input::INPUT_10000))); | |
c.bench_function("v1 batch deser big", |b| b.iter(|| types_v1(batch_input::INPUT_100000))); | |
c.bench_function("v2 batch deser small", |b| b.iter(|| types_v2(batch_input::INPUT_10))); | |
c.bench_function("v2 batch deser mid", |b| b.iter(|| types_v2(batch_input::INPUT_10000))); | |
c.bench_function("v2 batch deser big", |b| b.iter(|| types_v2(batch_input::INPUT_100000))); | |
} | |
v1 batch deser small time: [7.9906 us 8.0145 us 8.0402 us] | |
change: [-3.8833% -3.3602% -2.8086%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 5 outliers among 100 measurements (5.00%) | |
2 (2.00%) low mild | |
2 (2.00%) high mild | |
1 (1.00%) high severe | |
v1 batch deser mid time: [8.9144 ms 8.9329 ms 8.9556 ms] | |
change: [-3.8222% -3.5459% -3.2552%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 7 outliers among 100 measurements (7.00%) | |
5 (5.00%) high mild | |
2 (2.00%) high severe | |
Benchmarking v1 batch deser big: Warming up for 3.0000 s | |
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 10.6s, or reduce sample count to 40. | |
v1 batch deser big time: [104.05 ms 104.43 ms 104.95 ms] | |
change: [+3.8911% +4.5274% +5.1530%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 10 outliers among 100 measurements (10.00%) | |
6 (6.00%) high mild | |
4 (4.00%) high severe | |
v2 batch deser small time: [1.9333 us 1.9350 us 1.9367 us] | |
change: [-5.7017% -4.9078% -4.1767%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 13 outliers among 100 measurements (13.00%) | |
5 (5.00%) low severe | |
1 (1.00%) low mild | |
2 (2.00%) high mild | |
5 (5.00%) high severe | |
v2 batch deser mid time: [946.23 us 947.89 us 949.94 us] | |
change: [-11.940% -10.955% -10.130%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 15 outliers among 100 measurements (15.00%) | |
3 (3.00%) low severe | |
4 (4.00%) high mild | |
8 (8.00%) high severe | |
v2 batch deser big time: [9.2718 ms 9.2890 ms 9.3101 ms] | |
change: [-9.2157% -8.7695% -8.3211%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 3 outliers among 100 measurements (3.00%) | |
1 (1.00%) high mild | |
2 (2.00%) high severe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment