mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 15:55:45 +00:00
Add some additional decode benchmarks
This commit is contained in:
parent
903f674257
commit
c59e65d65b
@ -3,17 +3,30 @@ extern crate criterion;
|
||||
|
||||
use bytes::Bytes;
|
||||
use criterion::{black_box, Criterion};
|
||||
use sqlx_postgres_protocol::{Decode, Response};
|
||||
use sqlx_postgres_protocol::{Decode, ParameterStatus, BackendKeyData, Response};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
// NOTE: This is sans header (for direct decoding)
|
||||
const NOTICE_RESPONSE: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0";
|
||||
const PARAM_STATUS: &[u8] = b"session_authorization\0postgres\0";
|
||||
const BACKEND_KEY_DATA: &[u8] = b"\0\0'\xc6\x89R\xc5+";
|
||||
|
||||
c.bench_function("decode Response", |b| {
|
||||
b.iter(|| {
|
||||
let _ = Response::decode(black_box(Bytes::from_static(NOTICE_RESPONSE))).unwrap();
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("decode BackendKeyData", |b| {
|
||||
b.iter(|| {
|
||||
let _ = BackendKeyData::decode(black_box(Bytes::from_static(BACKEND_KEY_DATA))).unwrap();
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("decode ParameterStatus", |b| {
|
||||
b.iter(|| {
|
||||
let _ = ParameterStatus::decode(black_box(Bytes::from_static(PARAM_STATUS))).unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
@ -5,11 +5,10 @@ use criterion::Criterion;
|
||||
use sqlx_postgres_protocol::{Encode, PasswordMessage, Response, Severity, StartupMessage};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("encode Response(Builder)", |b| {
|
||||
c.bench_function("encode Response::builder()", |b| {
|
||||
let mut dst = Vec::new();
|
||||
b.iter(|| {
|
||||
dst.truncate(0);
|
||||
|
||||
dst.clear();
|
||||
Response::builder()
|
||||
.severity(Severity::Notice)
|
||||
.code("42710")
|
||||
@ -22,11 +21,10 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("encode Password(Cleartext)", |b| {
|
||||
c.bench_function("encode PasswordMessage::cleartext", |b| {
|
||||
let mut dst = Vec::new();
|
||||
b.iter(|| {
|
||||
dst.truncate(0);
|
||||
|
||||
dst.clear();
|
||||
PasswordMessage::cleartext("8e323AMF9YSE9zftFnuhQcvhz7Vf342W4cWU")
|
||||
.encode(&mut dst)
|
||||
.unwrap();
|
||||
@ -36,11 +34,15 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("encode StartupMessage", |b| {
|
||||
let mut dst = Vec::new();
|
||||
b.iter(|| {
|
||||
dst.truncate(0);
|
||||
|
||||
dst.clear();
|
||||
StartupMessage::builder()
|
||||
.param("user", "postgres")
|
||||
.param("database", "postgres")
|
||||
.param("DateStyle", "ISO, MDY")
|
||||
.param("IntervalStyle", "iso_8601")
|
||||
.param("TimeZone", "UTC")
|
||||
.param("extra_float_digits", "3")
|
||||
.param("client_encoding", "UTF-8")
|
||||
.build()
|
||||
.encode(&mut dst)
|
||||
.unwrap();
|
||||
@ -50,8 +52,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("encode Password(MD5)", |b| {
|
||||
let mut dst = Vec::new();
|
||||
b.iter(|| {
|
||||
dst.truncate(0);
|
||||
|
||||
dst.clear();
|
||||
PasswordMessage::md5(
|
||||
"8e323AMF9YSE9zftFnuhQcvhz7Vf342W4cWU",
|
||||
"postgres",
|
||||
|
@ -84,7 +84,7 @@ async fn receiver(
|
||||
mut reader: ReadHalf<TcpStream>,
|
||||
mut sender: mpsc::UnboundedSender<Message>,
|
||||
) -> io::Result<()> {
|
||||
let mut rbuf = BytesMut::with_capacity(0);
|
||||
let mut rbuf = BytesMut::with_capacity(1024);
|
||||
let mut len = 0;
|
||||
|
||||
loop {
|
||||
|
Loading…
x
Reference in New Issue
Block a user