diff --git a/Cargo.toml b/Cargo.toml index 6efaaa6c..2ccf58f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/benches/postgres_protocol.rs b/benches/postgres_protocol.rs new file mode 100644 index 00000000..4d93aac0 --- /dev/null +++ b/benches/postgres_protocol.rs @@ -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);