Created
August 4, 2019 02:22
-
-
Save sfackler/4188bf8789ac6eee50502f6331392711 to your computer and use it in GitHub Desktop.
This file contains 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
use criterion::{Bencher, Benchmark, Criterion}; | |
use postgres::{Client, NoTls}; | |
use postgres_sync::{Connection, TlsMode}; | |
fn prepare_new(b: &mut Bencher) { | |
let mut client = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap(); | |
b.iter(|| client.prepare("SELECT $1::TEXT").unwrap()); | |
} | |
fn prepare_old(b: &mut Bencher) { | |
let connection = | |
Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap(); | |
b.iter(|| connection.prepare("SELECT $1::TEXT").unwrap()); | |
} | |
fn query_prepared_new(b: &mut Bencher) { | |
let mut client = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap(); | |
let stmt = client.prepare("SELECT $1::TEXT").unwrap(); | |
b.iter(|| client.query(&stmt, &[&"hello world"]).unwrap()); | |
} | |
fn query_prepared_old(b: &mut Bencher) { | |
let connection = | |
Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap(); | |
let stmt = connection.prepare("SELECT $1::TEXT").unwrap(); | |
b.iter(|| stmt.query(&[&"hello world"]).unwrap()); | |
} | |
fn query_new(b: &mut Bencher) { | |
let mut client = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap(); | |
b.iter(|| client.query("SELECT $1::TEXT", &[&"hello world"]).unwrap()); | |
} | |
fn query_old(b: &mut Bencher) { | |
let connection = | |
Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap(); | |
b.iter(|| { | |
connection | |
.query("SELECT $1::TEXT", &[&"hello world"]) | |
.unwrap() | |
}); | |
} | |
fn main() { | |
Criterion::default() | |
.configure_from_args() | |
.bench( | |
"prepare", | |
Benchmark::new("new", prepare_new).with_function("old", prepare_old), | |
) | |
.bench( | |
"query_prepared", | |
Benchmark::new("new", query_prepared_new).with_function("old", query_prepared_old), | |
) | |
.bench( | |
"query", | |
Benchmark::new("new", query_new).with_function("old", query_old), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment