Created
April 2, 2026 12:39
-
-
Save hugobarauna/369f68acf4292f27309782ba774b8988 to your computer and use it in GitHub Desktop.
Benchmark: Dux flat SQL for single-op pipelines (PR #50)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Benchmark: flat SQL for single-op pipelines | |
| # | |
| # Usage: mix run bench_flat_sql.exs | |
| require Dux | |
| num_rows = 1_000_000 | |
| IO.puts("Generating #{num_rows} rows...") | |
| data = | |
| Enum.map(1..num_rows, fn _ -> | |
| %{ | |
| region: Enum.random(~w(North South East West Central)), | |
| product: Enum.random(~w(Widget Gadget Doohickey Thingamajig Gizmo)), | |
| quantity: :rand.uniform(100), | |
| price: Float.round(:rand.uniform() * 500, 2), | |
| date: Date.from_iso8601!("2025-01-15") | |
| } | |
| end) | |
| dux = Dux.from_list(data) |> Dux.compute() | |
| IO.puts("Running benchmarks...\n") | |
| Benchee.run( | |
| %{ | |
| "compute: filter" => fn -> | |
| dux |> Dux.filter(quantity > 50 and price > 100.0) |> Dux.compute() | |
| end, | |
| "compute: mutate" => fn -> | |
| dux |> Dux.mutate(revenue: quantity * price) |> Dux.compute() | |
| end, | |
| "compute: group_by+summarise" => fn -> | |
| dux | |
| |> Dux.group_by(:region) | |
| |> Dux.summarise(total: sum(quantity), avg_price: avg(price)) | |
| |> Dux.compute() | |
| end, | |
| "e2e: filter → to_rows" => fn -> | |
| dux |> Dux.filter(quantity > 50 and price > 100.0) |> Dux.to_rows() | |
| end, | |
| "e2e: summarise → to_rows" => fn -> | |
| dux | |
| |> Dux.group_by(:region) | |
| |> Dux.summarise(total: sum(quantity), avg_price: avg(price)) | |
| |> Dux.to_rows() | |
| end | |
| }, | |
| warmup: 2, | |
| time: 5, | |
| memory_time: 0 | |
| ) | |
| _ = dux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment