diff --git a/benches/README.md b/benches/README.md index bd2ccf9..d39bc8a 100644 --- a/benches/README.md +++ b/benches/README.md @@ -23,8 +23,7 @@ Then upload the `perf.script` file to [Firefox Profiler](https://profiler.firefo These benchmarks are run against a real ClickHouse server, so it must be started: ```bash -docker run -d -p 8123:8123 -p 9000:9000 --name ch clickhouse/clickhouse-server - +docker compose up -d cargo bench --bench ``` diff --git a/benches/select.rs b/benches/select.rs index 316015e..f6e7cd2 100644 --- a/benches/select.rs +++ b/benches/select.rs @@ -61,7 +61,7 @@ fn select(c: &mut Criterion) { d: u32, } - async fn run(client: Client, iters: u64) -> Result { + async fn select_rows(client: Client, iters: u64) -> Result { let start = Instant::now(); let mut cursor = client .query("SELECT ?fields FROM some") @@ -74,14 +74,51 @@ fn select(c: &mut Criterion) { Ok(start.elapsed()) } - let mut group = c.benchmark_group("select"); + async fn select_bytes(client: Client, min_size: u64) -> Result { + let start = Instant::now(); + let mut cursor = client + .query("SELECT value FROM some") + .fetch_bytes("RowBinary")?; + + let mut size = 0; + while size < min_size { + let buf = black_box(cursor.next().await?); + size += buf.unwrap().len() as u64; + } + + Ok(start.elapsed()) + } + + let mut group = c.benchmark_group("rows"); group.throughput(Throughput::Bytes(mem::size_of::() as u64)); - group.bench_function("no compression", |b| { + group.bench_function("uncompressed", |b| { + b.iter_custom(|iters| { + let client = Client::default() + .with_url(format!("http://{addr}")) + .with_compression(Compression::None); + runner.run(select_rows(client, iters)) + }) + }); + #[cfg(feature = "lz4")] + group.bench_function("lz4", |b| { + b.iter_custom(|iters| { + let client = Client::default() + .with_url(format!("http://{addr}")) + .with_compression(Compression::Lz4); + runner.run(select_rows(client, iters)) + }) + }); + group.finish(); + + const MIB: u64 = 1024 * 1024; + let mut group = c.benchmark_group("mbytes"); + group.throughput(Throughput::Bytes(MIB)); + group.bench_function("uncompressed", |b| { b.iter_custom(|iters| { let client = Client::default() .with_url(format!("http://{addr}")) .with_compression(Compression::None); - runner.run(run(client, iters)) + runner.run(select_bytes(client, iters * MIB)) }) }); #[cfg(feature = "lz4")] @@ -90,7 +127,7 @@ fn select(c: &mut Criterion) { let client = Client::default() .with_url(format!("http://{addr}")) .with_compression(Compression::Lz4); - runner.run(run(client, iters)) + runner.run(select_bytes(client, iters * MIB)) }) }); group.finish();