mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 23:35:20 +00:00
Add a few protocol codec benchmarks
This commit is contained in:
parent
067f1e613c
commit
d6e9c47da8
@ -36,6 +36,7 @@ uuid = { version = "0.8.1", optional = true }
|
||||
matches = "0.1.8"
|
||||
tokio = { version = "0.2.0-alpha.4", default-features = false, features = [ "rt-full" ] }
|
||||
sqlx-macros = { path = "sqlx-macros/" }
|
||||
criterion = "0.3"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
@ -44,3 +45,8 @@ codegen-units = 1
|
||||
[[test]]
|
||||
name = "sql-macro-test"
|
||||
required-features = ["uuid"]
|
||||
|
||||
[[bench]]
|
||||
name = "postgres_protocol"
|
||||
required-features = ["postgres", "unstable"]
|
||||
harness = false
|
||||
|
37
benches/postgres_protocol.rs
Normal file
37
benches/postgres_protocol.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use sqlx::postgres::protocol::{Bind, DataRow, RowDescription};
|
||||
use sqlx::postgres::protocol::{Encode, Decode};
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
c.bench_function("decode_data_row", |b| {
|
||||
b.iter(|| {
|
||||
let _ = DataRow::decode(&black_box(b"\0\x03\0\0\0\x011\0\0\0\x012\0\0\0\x013")[..]);
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function( "decode_row_description",|b| {
|
||||
b.iter(|| {
|
||||
let _ = RowDescription::decode(&black_box(b"\0\x02user_id\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0number_of_pages\0\0\0\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\0\0")[..]);
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("encode_bind", |b| {
|
||||
let mut buf = Vec::new();
|
||||
|
||||
b.iter(|| {
|
||||
black_box(Bind {
|
||||
portal: "__sqlx_portal_5121",
|
||||
statement: "__sqlx_statement_5121",
|
||||
formats: &[1],
|
||||
values_len: 2,
|
||||
values: &[(-1_i8) as _, 0, 0, 0, 1, 0, 0, 0, 25],
|
||||
result_formats: &[1],
|
||||
}).encode(&mut buf);
|
||||
|
||||
buf.clear();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
Loading…
x
Reference in New Issue
Block a user