Skip to content

Apache DataFusion SQL Query Engine

ARROW-11254: [Rust][DataFusion] Add SIMD and snmalloc flags as options to benchmarks

Daniël Heres82773fafcb48
diff --git a/rust/benchmarks/Cargo.toml b/rust/benchmarks/Cargo.toml
index 66949a1d17..e29fb38d50 100644
--- a/rust/benchmarks/Cargo.toml
+++ b/rust/benchmarks/Cargo.toml
@@ -26,6 +26,10 @@ repository = "https://github.com/apache/arrow"
license = "Apache-2.0"
publish = false
+[features]
+simd = ["datafusion/simd"]
+snmalloc = ["snmalloc-rs"]
+
[dependencies]
arrow = { path = "../arrow" }
parquet = { path = "../parquet" }
@@ -33,4 +37,5 @@ datafusion = { path = "../datafusion" }
structopt = { version = "0.3", default-features = false }
tokio = { version = "0.2", features = ["macros", "rt-core", "rt-threaded"] }
futures = "0.3"
-env_logger = "^0.8"
\ No newline at end of file
+env_logger = "^0.8"
+snmalloc-rs = {version = "0.2", optional = true, features= ["cache-friendly"] }
diff --git a/rust/benchmarks/README.md b/rust/benchmarks/README.md
index 2ae035b9fc..bb56b75a1b 100644
--- a/rust/benchmarks/README.md
+++ b/rust/benchmarks/README.md
@@ -53,6 +53,12 @@ The benchmark can then be run (assuming the data created from `dbgen` is in `/mn
cargo run --release --bin tpch -- benchmark --iterations 3 --path /mnt/tpch-dbgen --format tbl --query 1 --batch-size 4096
```
+You can enable the features `simd` (to use SIMD instructions) and/or `snmalloc` (to use the snmalloc allocator) as features by passing them in as `--features`:
+
+```
+cargo run --release --features "simd snmalloc" --bin tpch -- benchmark --iterations 3 --path /mnt/tpch-dbgen --format tbl --query 1 --batch-size 4096
+```
+
The benchmark program also supports CSV and Parquet input file formats and a utility is provided to convert from `tbl`
(generated by the `dbgen` utility) to CSV and Parquet.
diff --git a/rust/benchmarks/src/bin/nyctaxi.rs b/rust/benchmarks/src/bin/nyctaxi.rs
index a3cac44afc..3391c38c8d 100644
--- a/rust/benchmarks/src/bin/nyctaxi.rs
+++ b/rust/benchmarks/src/bin/nyctaxi.rs
@@ -31,6 +31,10 @@ use datafusion::physical_plan::collect;
use datafusion::physical_plan::csv::CsvReadOptions;
use structopt::StructOpt;
+#[cfg(feature = "snmalloc")]
+#[global_allocator]
+static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
+
#[derive(Debug, StructOpt)]
#[structopt(name = "Benchmarks", about = "Apache Arrow Rust Benchmarks.")]
struct Opt {
diff --git a/rust/benchmarks/src/bin/tpch.rs b/rust/benchmarks/src/bin/tpch.rs
index 539b8d23d0..835c89396c 100644
--- a/rust/benchmarks/src/bin/tpch.rs
+++ b/rust/benchmarks/src/bin/tpch.rs
@@ -33,6 +33,10 @@ use parquet::basic::Compression;
use parquet::file::properties::WriterProperties;
use structopt::StructOpt;
+#[cfg(feature = "snmalloc")]
+#[global_allocator]
+static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
+
#[derive(Debug, StructOpt)]
struct BenchmarkOpt {
/// Query number