rust-postgres/postgres/benches/bench.rs
Steven Fackler 09a63d6255 Move to local runtimes per connection
This avoids a bunch of context switches and cross-thread
synchronization, which ends up improving the performance of a simple
query by ~20%, from 252us to 216us.
2019-12-03 18:25:29 -08:00

18 lines
531 B
Rust

use criterion::{criterion_group, criterion_main, Criterion};
use postgres::{Client, NoTls};
// spawned: 249us 252us 255us
// local: 214us 216us 219us
fn query_prepared(c: &mut Criterion) {
let mut client = Client::connect("host=localhost port=5433 user=postgres", NoTls).unwrap();
let stmt = client.prepare("SELECT $1::INT8").unwrap();
c.bench_function("query_prepared", move |b| {
b.iter(|| client.query(&stmt, &[&1i64]).unwrap())
});
}
criterion_group!(group, query_prepared);
criterion_main!(group);