Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ SET(DAS_SIMULATE_INCLUDES
include/daScript/simulate/bind_enum.h
include/daScript/simulate/bin_serializer.h
include/daScript/simulate/cast.h
include/daScript/simulate/das_qsort_r.h
include/daScript/simulate/data_walker.h
include/daScript/simulate/debug_info.h
include/daScript/simulate/debug_print.h
Expand Down
137 changes: 81 additions & 56 deletions benchmarks/sql/LINQ.md

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions benchmarks/sql/all_match.das
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let yes = _old_fold(each(arr)._all(_.price < 9999))
if (!yes) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -61,11 +50,6 @@ def all_match_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def all_match_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def all_match_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
16 changes: 0 additions & 16 deletions benchmarks/sql/any_match.das
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let yes = _old_fold(each(arr)._any(_.price > THRESHOLD))
if (!yes) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -61,11 +50,6 @@ def any_match_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def any_match_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def any_match_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
18 changes: 1 addition & 17 deletions benchmarks/sql/average_aggregate.das
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ options persistent_heap
require _common public

// SQL: SELECT AVG(price) FROM Cars.
// m3/m3f_old/m3f sum and divide on a single pass.
// m3/m3f sum and divide on a single pass.

def run_m1(b : B?; n : int) {
with_sqlite(":memory:") $(db) {
Expand All @@ -27,17 +27,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let a = _old_fold(each(arr)._select(double(_.price)).average())
if (a == 0.0lf) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -58,11 +47,6 @@ def average_aggregate_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def average_aggregate_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def average_aggregate_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
64 changes: 64 additions & 0 deletions benchmarks/sql/bare_order_where.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
options gen2
options persistent_heap

require _common public

let THRESHOLD = 500

// _where(_.price > T) |> _order_by(_.price) — fused prefilter + sort, NO take.
// SQL: WHERE price > T ORDER BY price.
// m3 (plain LINQ) materializes a filter array, then sorts a clone (two allocations).
// m3f (spliced via plan_order_family Phase 3c) emits a single fused loop that collects
// matching elements into one pre-allocated buffer, then sort_inplace's the buffer.

def run_m1(b : B?; n : int) {
with_sqlite(":memory:") $(db) {
fixture_db(db, n)
b |> run("m1_sql/{n}", n) {
let rows <- _sql(db |> select_from(type<Car>)
|> _where(_.price > THRESHOLD)
|> _order_by(_.price))
if (empty(rows)) {
b->failNow()
}
}
}
}

def run_m3(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3_array/{n}", n) {
let rows <- (arr |> _where(_.price > THRESHOLD)
|> _order_by(_.price))
if (empty(rows)) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
let rows <- _fold(each(arr)._where(_.price > THRESHOLD)
._order_by(_.price)
.to_array())
if (empty(rows)) {
b->failNow()
}
}
}

[benchmark]
def bare_order_where_m1(b : B?) {
run_m1(b, 100000)
}

[benchmark]
def bare_order_where_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def bare_order_where_m3f(b : B?) {
run_m3f(b, 100000)
}
18 changes: 0 additions & 18 deletions benchmarks/sql/chained_where.das
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let c = _old_fold(each(arr)._where(_.price > THRESHOLD)
._where(_.year >= YEAR_FLOOR)
.count())
if (c == 0) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -72,11 +59,6 @@ def chained_where_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def chained_where_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def chained_where_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
16 changes: 0 additions & 16 deletions benchmarks/sql/contains_match.das
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let yes = _old_fold(each(arr)._select(_.id).contains(TARGET_ID))
if (!yes) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -64,11 +53,6 @@ def contains_match_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def contains_match_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def contains_match_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
17 changes: 0 additions & 17 deletions benchmarks/sql/count_aggregate.das
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let THRESHOLD = 500

// SQL pushes COUNT(*) to the engine returning one row.
// m3 must materialize the full filtered array, then walk to count it.
// m3f_old is the pre-rewrite baseline fold (frozen — diverges as splice mode lands).
// m3f folds where+count into a single fused pass (no intermediate array).

// --- m1: _sql over :memory: ---
Expand All @@ -34,17 +33,6 @@ def run_m3(b : B?; n : int) {
}
}

// --- m3f_old: pre-rewrite baseline fold ---
def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let c = _old_fold(each(arr)._where(_.price > THRESHOLD).count())
if (c == 0) {
b->failNow()
}
}
}

// --- m3f: array LINQ folded into a single fused pass ---
def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
Expand All @@ -66,11 +54,6 @@ def count_aggregate_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def count_aggregate_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def count_aggregate_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
16 changes: 0 additions & 16 deletions benchmarks/sql/distinct_count.das
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let rows <- _old_fold(each(arr)._select(_.brand).distinct().to_array())
if (empty(rows)) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -62,11 +51,6 @@ def distinct_count_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def distinct_count_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def distinct_count_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
20 changes: 2 additions & 18 deletions benchmarks/sql/first_match.das
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ let THRESHOLD = 500

// SQL: SELECT ... LIMIT 1 — engine stops at first hit.
// m3 materializes the full filtered array then indexes [0].
// m3f_old / m3f should ideally early-exit at the first matching row;
// splice mode is the main target here.
// m3f should ideally early-exit at the first matching row; splice mode
// is the main target here.

def run_m1(b : B?; n : int) {
with_sqlite(":memory:") $(db) {
Expand All @@ -31,17 +31,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_old_array_fold/{n}", n) {
let row = _old_fold(each(arr)._where(_.price > THRESHOLD).first())
if (row.price == 0) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
b |> run("m3f_array_fold/{n}", n) {
Expand All @@ -62,11 +51,6 @@ def first_match_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def first_match_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def first_match_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
17 changes: 0 additions & 17 deletions benchmarks/sql/first_or_default_match.das
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ def run_m3(b : B?; n : int) {
}
}
}

def run_m3f_old(b : B?; n : int) {
let arr <- fixture_array(n)
let sentinel = Car(id = SENTINEL_ID, name = "none", price = 0, brand = 0, year = 0, dealer_id = 0)
b |> run("m3f_old_array_fold/{n}", n) {
let row = _old_fold(each(arr)._where(_.price > THRESHOLD).first_or_default(sentinel))
if (row.id == SENTINEL_ID) {
b->failNow()
}
}
}

def run_m3f(b : B?; n : int) {
let arr <- fixture_array(n)
let sentinel = Car(id = SENTINEL_ID, name = "none", price = 0, brand = 0, year = 0, dealer_id = 0)
Expand All @@ -65,11 +53,6 @@ def first_or_default_match_m3(b : B?) {
run_m3(b, 100000)
}

[benchmark]
def first_or_default_match_m3f_old(b : B?) {
run_m3f_old(b, 100000)
}

[benchmark]
def first_or_default_match_m3f(b : B?) {
run_m3f(b, 100000)
Expand Down
Loading
Loading