kazantsev-maksim commented on code in PR #4744:
URL: https://github.com/apache/datafusion-comet/pull/4744#discussion_r3791612539


##########
spark/src/test/scala/org/apache/spark/sql/benchmark/CometArrayFilterBenchmark.scala:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.sql.benchmark
+
+import org.apache.spark.benchmark.Benchmark
+
+import org.apache.comet.CometConf
+
+// spotless:off
+/**
+ * Benchmark to measure performance of Comet array expressions. To run this 
benchmark:
+ * {{{
+ *   SPARK_GENERATE_BENCHMARK_FILES=1 make 
benchmark-org.apache.spark.sql.benchmark.CometArrayFilterBenchmark
+ * }}}
+ * Results will be written to 
"spark/benchmarks/CometArrayFilterBenchmark-**results.txt".
+ */
+// spotless:on
+object CometArrayFilterBenchmark extends CometBenchmarkBase {
+
+  def runExprBenchmark(config: ArrayFilterExprConfig, values: Int, arraySize: 
Int): Unit = {
+    val benchmark =
+      new Benchmark(s"${config.name} (size $arraySize)", values, output = 
output)
+    withTempPath { dir =>
+      withTempTable("parquetV1Table") {
+        prepareTable(
+          dir,
+          spark.sql(
+            s"SELECT sequence(0, cast(rand(42) * $arraySize as int)) AS arr " +
+              s"FROM range($values)"))
+
+        benchmark.addCase(s"Spark ${config.name}") { _ =>
+          withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+            spark.sql(config.query).noop()
+          }
+        }
+
+        benchmark.addCase(s"Comet (Native) ${config.name}") { _ =>
+          withSQLConf(
+            CometConf.COMET_ENABLED.key -> "true",
+            CometConf.COMET_EXEC_ENABLED.key -> "true",
+            CometConf.COMET_SCALA_UDF_CODEGEN_ENABLED.key -> "false") {
+            spark.sql(config.query).noop()
+          }
+        }
+
+        benchmark.addCase(s"Comet (Codegen) ${config.name}") { _ =>
+          withSQLConf(
+            CometConf.COMET_ENABLED.key -> "true",
+            CometConf.COMET_EXEC_ENABLED.key -> "true",
+            CometConf.COMET_SCALA_UDF_CODEGEN_ENABLED.key -> "true") {
+            spark.sql(config.query).noop()
+          }
+        }
+
+        benchmark.run()
+      }
+    }
+  }
+
+  def runCometBenchmark(args: Array[String]): Unit = {
+    val values = 4 * 1024 * 1024
+
+    val config =
+      ArrayFilterExprConfig("array_filter", "SELECT filter(arr, x -> x > 2) 
FROM parquetV1Table")
+
+    runExprBenchmark(config, values, 100)

Review Comment:
   I have updated `CometArrayFilterBenchmark` to cover a comprehensive set of 
shapes, including:
   - Outer column capture (`x -> x > threshold`)
   - String predicates (`length(x) > 10`, string equality)
   - Compound boolean logic & arithmetic inside lambda
   - Nullable element propagation (`IS NOT NULL`)
   - Nested arrays (`array<array<int>>`)
   - Chained filters pipeline & large SIMD-friendly arrays
   
   ### Benchmark Results (Apple M1 Pro, 4M rows)
   
   | Benchmark Case | Spark (ms) | Comet Native (ms) | Comet Codegen (ms) | 
Relative (vs Spark) |
   | :--- | :---: | :---: | :---: | :---: |
   | **int literal** | 4961 | 1083 | 1129 | **4.6x** |
   | **capture outer col** | 5706 | 1110 | 1093 | **5.1x** |
   | **compound predicate** | 7939 | 1123 | 1125 | **7.1x** |
   | **arithmetic in lambda** | 8168 | 1227 | 1227 | **6.7x** |
   | **string length** | 20797 | 2172 | 2144 | **9.6x** |
   | **string equality** | 11769 | 2641 | 2639 | **4.5x** |
   | **array with nulls** | 7897 | 1486 | 1488 | **5.3x** |
   | **nested array** | 3705 | 973 | 971 | **3.8x** |
   | **chained filters** | 9388 | 1587 | 1613 | **5.9x** |
   | **short arrays** | 942 | 203 | 198 | **4.6x** |
   | **large arrays (size 1000)** | 58994 | 11071 | 11317 | **5.3x** |
   
   Comet consistently delivers **3.8x–9.6x** speedups across all shapes. The 
native DataFusion path matches and occasionally edges out JVM codegen 
performance.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to