rust-postgres/benches/bench.rs
Steven Fackler 348195b718 Optimize execute
Avoiding the statment close by using the unnamed statment improves the
lower bound perf by ~1/3:

test bench_execute        ... bench:    425429 ns/iter (+/- 24970)
test bench_naiive_execute ... bench:    607967 ns/iter (+/- 53434)

cc #83
2014-12-01 22:24:31 -08:00

30 lines
812 B
Rust

extern crate test;
extern crate postgres;
use test::Bencher;
use postgres::{Connection, SslMode};
#[bench]
fn bench_naiive_execute(b: &mut test::Bencher) {
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]).unwrap();
b.iter(|| {
let stmt = conn.prepare("UPDATE foo SET id = 1").unwrap();
let out = stmt.execute(&[]).unwrap();
stmt.finish().unwrap();
out
});
}
#[bench]
fn bench_execute(b: &mut test::Bencher) {
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]).unwrap();
b.iter(|| {
conn.execute("UPDATE foo SET id = 1", &[]).unwrap()
});
}