Skip to content

Commit ec78ede

Browse files
authored
Merge pull request #296 from array2d/benchmark/compact-matmul-quicksort
benchmark: matmul/quicksort 改用 compact 形式,移除 _compact 目录
2 parents 1b6127d + b4535e5 commit ec78ede

10 files changed

Lines changed: 40 additions & 366 deletions

File tree

benchmark/cases/matmul/matmul.kv

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
// matrix multiplication benchmark — 稠密方阵乘(浮点运算 + 三重循环)
2-
// A/B 元素取 0.25 倍数(二进制精确),C 校验和 × 1e6 恒为精确整数、跨语言逐字节一致
1+
// matrix multiplication benchmark(compact 形式)— 同 matmul 算法,矩阵落**单个 compact XValue**
2+
//`[N,N]float64`,storetype=ARRAYND,元素连续打包),而非散 key 的 `[int64]·float64` map
3+
// 对比点:同一算法的两种 kv 物理形态——map 每次元素访问一次 KV 往返,compact 一次 xv·at/set
34
// 方阵阶 N 由 __SCALE__ 占位(O(N^3),勿改逻辑)
45
// 期望输出(N=6 时):
5-
// matmul: check = 82750000
6+
// matmul_compact: check = 82750000
67
rwfunc test() -> () {
78
__SCALE__ -> n
8-
A:[int64]·float64 = {}
9-
B:[int64]·float64 = {}
9+
A:[__SCALE__,__SCALE__]float64 = []
10+
B:[__SCALE__,__SCALE__]float64 = []
1011
0 -> i
1112
while (i < n) {
1213
0 -> j
1314
while (j < n) {
14-
i × n -> base
15-
base + j -> idx
1615
i + j -> ta
1716
ta % 4 -> qa
1817
float64(qa) -> qaf
1918
qaf × 0.25 -> pa
2019
pa + 0.25 -> av
21-
av -> A·*idx
20+
av -> A[i, j]
2221
i × 2 -> i2
2322
i2 + j -> tb
2423
tb % 4 -> qb
2524
float64(qb) -> qbf
2625
qbf × 0.25 -> pb
2726
pb + 0.25 -> bv
28-
bv -> B·*idx
27+
bv -> B[i, j]
2928
j + 1 -> j
3029
}
3130
i + 1 -> i
@@ -39,12 +38,8 @@ rwfunc test() -> () {
3938
0.0 -> acc
4039
0 -> k
4140
while (k < n) {
42-
i × n -> ba
43-
ba + k -> ia
44-
kv·get(A, ia) -> av
45-
k × n -> bb
46-
bb + j -> ib
47-
kv·get(B, ib) -> bv
41+
A[i, k] -> av
42+
B[k, j] -> bv
4843
av × bv -> pr
4944
acc + pr -> acc
5045
k + 1 -> k
@@ -57,7 +52,7 @@ rwfunc test() -> () {
5752
t1 = time·now()
5853
checksum × 1000000.0 -> scaled
5954
int64(scaled) -> out
60-
println("matmul: check =", out)
55+
println("matmul_compact: check =", out)
6156
delta = time·sub(t1, t0)
6257
ns = time/duration·as_nanos(delta)
6358
println("__bench_ns:", ns)

benchmark/cases/matmul_compact/matmul_compact.c

Lines changed: 0 additions & 32 deletions
This file was deleted.

benchmark/cases/matmul_compact/matmul_compact.kv

Lines changed: 0 additions & 60 deletions
This file was deleted.

benchmark/cases/matmul_compact/matmul_compact.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

benchmark/cases/matmul_compact/matmul_compact.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

benchmark/cases/quicksort/quicksort.kv

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
1-
// quicksort benchmark — 迭代 Lomuto 分区就地排序(数组访问 + 显式栈递归)
1+
// quicksort benchmark(compact 形式)— 同 quicksort 算法,待排数组与显式栈都落**单个 compact
2+
// XValue**`[N]int64`,storetype=ARRAYND),而非散 key 的 `[int64]·int64` map
3+
// 对比点:同一算法的两种 kv 物理形态。
24
// 数据由 LCG 确定生成,规模 N 由 __SCALE__ 占位,run.py 按扫描点替换(勿改逻辑)
35
// 期望输出(N=64 时):
4-
// qsort: a0 = 1 amid = 52 alast = 99
6+
// qsort_compact: a0 = 1 amid = 52 alast = 99
57
rwfunc test() -> () {
68
__SCALE__ -> n
7-
arr:[int64]·int64 = {}
9+
arr:[__SCALE__]int64 = []
810
1 -> seed
911
0 -> i
1012
while (i < n) {
1113
seed × 1103515245 -> s1
1214
s1 + 12345 -> s2
1315
s2 % 2147483648 -> seed
1416
seed % 100 -> v
15-
v -> arr·*i
17+
v -> arr[i]
1618
i + 1 -> i
1719
}
1820
t0 = time·now()
19-
st_lo:[int64]·int64 = {}
20-
st_hi:[int64]·int64 = {}
21+
// 显式栈也用 compact:与待排数组一样落单个 ARRAYND XValue,全程只在 compact 数组里直接交换。
22+
st_lo:[__SCALE__]int64 = []
23+
st_hi:[__SCALE__]int64 = []
2124
0 -> top
22-
0 -> st_lo·*top
23-
n - 1 -> st_hi·*top
25+
0 -> st_lo[top]
26+
n - 1 -> st_hi[top]
2427
top + 1 -> top
2528
while (top > 0) {
2629
top - 1 -> top
27-
kv·get(st_lo, top) -> lo
28-
kv·get(st_hi, top) -> hi
30+
st_lo[top] -> lo
31+
st_hi[top] -> hi
2932
if (lo < hi) {
30-
kv·get(arr, hi) -> pivot
33+
arr[hi] -> pivot
3134
lo - 1 -> ii
3235
lo -> jj
3336
while (jj < hi) {
34-
kv·get(arr, jj) -> aj
37+
arr[jj] -> aj
3538
if (aj <= pivot) {
3639
ii + 1 -> ii
37-
kv·get(arr, ii) -> ai
38-
aj -> arr·*ii
39-
ai -> arr·*jj
40+
arr[ii] -> ai
41+
aj -> arr[ii]
42+
ai -> arr[jj]
4043
}
4144
jj + 1 -> jj
4245
}
4346
ii + 1 -> pp
44-
kv·get(arr, pp) -> app
45-
pivot -> arr·*pp
46-
app -> arr·*hi
47-
lo -> st_lo·*top
48-
pp - 1 -> st_hi·*top
47+
arr[pp] -> app
48+
pivot -> arr[pp]
49+
app -> arr[hi]
50+
lo -> st_lo[top]
51+
pp - 1 -> st_hi[top]
4952
top + 1 -> top
50-
pp + 1 -> st_lo·*top
51-
hi -> st_hi·*top
53+
pp + 1 -> st_lo[top]
54+
hi -> st_hi[top]
5255
top + 1 -> top
5356
}
5457
}
5558
t1 = time·now()
5659
n ÷ 2 -> mid
5760
n - 1 -> last
58-
kv·get(arr, 0) -> a0
59-
kv·get(arr, mid) -> am
60-
kv·get(arr, last) -> al
61-
println("qsort: a0 =", a0, "amid =", am, "alast =", al)
61+
arr[0] -> a0
62+
arr[mid] -> am
63+
arr[last] -> al
64+
println("qsort_compact: a0 =", a0, "amid =", am, "alast =", al)
6265
delta = time·sub(t1, t0)
6366
ns = time/duration·as_nanos(delta)
6467
println("__bench_ns:", ns)

benchmark/cases/quicksort_compact/quicksort_compact.c

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)