You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by ag...@apache.org on 2024/06/13 20:21:47 UTC

(datafusion-comet) branch main updated: perf: Add criterion benchmark for xxhash64 function (#560)

This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new f95d386a perf: Add criterion benchmark for xxhash64 function (#560)
f95d386a is described below

commit f95d386afc1976cd7c30cd81abf648397e510f95
Author: Andy Grove <ag...@apache.org>
AuthorDate: Thu Jun 13 14:21:42 2024 -0600

    perf: Add criterion benchmark for xxhash64 function (#560)
    
    * add benchmark for xxhash64
    
    * remove new code
    
    * add murmur3 bench
    
    * format
    
    * fix
---
 core/benches/hash.rs                               | 26 ++++++++++++++++++++++
 .../datafusion/expressions/scalar_funcs.rs         |  2 +-
 core/src/execution/datafusion/mod.rs               |  2 +-
 core/src/execution/datafusion/spark_hash.rs        |  2 +-
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/core/benches/hash.rs b/core/benches/hash.rs
index dafad79d..b878ebea 100644
--- a/core/benches/hash.rs
+++ b/core/benches/hash.rs
@@ -19,9 +19,13 @@
 mod common;
 
 use arrow_array::ArrayRef;
+use comet::execution::datafusion::expressions::scalar_funcs::spark_murmur3_hash;
+use comet::execution::datafusion::spark_hash::create_xxhash64_hashes;
 use comet::execution::kernels::hash;
 use common::*;
 use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+use datafusion_common::ScalarValue;
+use datafusion_expr::ColumnarValue;
 use std::sync::Arc;
 
 const BATCH_SIZE: usize = 1024 * 8;
@@ -95,6 +99,28 @@ fn criterion_benchmark(c: &mut Criterion) {
             });
         },
     );
+    group.bench_function(BenchmarkId::new("xxhash64", BATCH_SIZE), |b| {
+        let input = vec![a3.clone(), a4.clone()];
+        let mut dst = vec![0; BATCH_SIZE];
+
+        b.iter(|| {
+            for _ in 0..NUM_ITER {
+                create_xxhash64_hashes(&input, &mut dst).unwrap();
+            }
+        });
+    });
+    group.bench_function(BenchmarkId::new("murmur3", BATCH_SIZE), |b| {
+        let inputs = &[
+            ColumnarValue::Array(a3.clone()),
+            ColumnarValue::Array(a4.clone()),
+            ColumnarValue::Scalar(ScalarValue::Int32(Some(42))),
+        ];
+        b.iter(|| {
+            for _ in 0..NUM_ITER {
+                spark_murmur3_hash(inputs).unwrap();
+            }
+        });
+    });
 }
 
 fn config() -> Criterion {
diff --git a/core/src/execution/datafusion/expressions/scalar_funcs.rs b/core/src/execution/datafusion/expressions/scalar_funcs.rs
index c50f0664..3c7af867 100644
--- a/core/src/execution/datafusion/expressions/scalar_funcs.rs
+++ b/core/src/execution/datafusion/expressions/scalar_funcs.rs
@@ -636,7 +636,7 @@ fn spark_decimal_div(
     Ok(ColumnarValue::Array(Arc::new(result)))
 }
 
-fn spark_murmur3_hash(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> {
+pub fn spark_murmur3_hash(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> {
     let length = args.len();
     let seed = &args[length - 1];
     match seed {
diff --git a/core/src/execution/datafusion/mod.rs b/core/src/execution/datafusion/mod.rs
index 2c6b2bf1..e98e4ed4 100644
--- a/core/src/execution/datafusion/mod.rs
+++ b/core/src/execution/datafusion/mod.rs
@@ -21,5 +21,5 @@ pub mod expressions;
 mod operators;
 pub mod planner;
 pub mod shuffle_writer;
-mod spark_hash;
+pub mod spark_hash;
 mod util;
diff --git a/core/src/execution/datafusion/spark_hash.rs b/core/src/execution/datafusion/spark_hash.rs
index 4d91a87d..a31752d4 100644
--- a/core/src/execution/datafusion/spark_hash.rs
+++ b/core/src/execution/datafusion/spark_hash.rs
@@ -481,7 +481,7 @@ pub(crate) fn create_murmur3_hashes<'a>(
 ///
 /// The number of rows to hash is determined by `hashes_buffer.len()`.
 /// `hashes_buffer` should be pre-sized appropriately
-pub(crate) fn create_xxhash64_hashes<'a>(
+pub fn create_xxhash64_hashes<'a>(
     arrays: &[ArrayRef],
     hashes_buffer: &'a mut [u64],
 ) -> Result<&'a mut [u64]> {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org