2025-08-27 17:06:46 +09:00
|
|
|
// Nyash simple benchmarks - just measure iterations without timer
|
|
|
|
|
// How to run:
|
2025-11-06 15:41:52 +09:00
|
|
|
// - Interpreter: ./target/release/nyash examples/ny_bench_simple.hako
|
|
|
|
|
// - VM: ./target/release/nyash --backend vm examples/ny_bench_simple.hako
|
|
|
|
|
// - VM+JIT (fast path!): NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 ./target/release/nyash --backend vm examples/ny_bench_simple.hako
|
2025-08-27 17:06:46 +09:00
|
|
|
|
|
|
|
|
local ITER
|
|
|
|
|
ITER = 100000 // change for heavier runs
|
|
|
|
|
|
|
|
|
|
print("\n=== Nyash Simple Benchmarks (ITER=" + ITER + ") ===")
|
|
|
|
|
|
|
|
|
|
// 1) Simple arithmetic loop: sum 0..ITER-1
|
|
|
|
|
local i, sum
|
|
|
|
|
i = 0
|
|
|
|
|
sum = 0
|
|
|
|
|
loop(i < ITER) {
|
|
|
|
|
sum = sum + i
|
|
|
|
|
i = i + 1
|
|
|
|
|
}
|
|
|
|
|
print("[arith_loop] sum = " + sum)
|
|
|
|
|
|
|
|
|
|
// 2) Array push loop: push integers 0..ITER-1
|
|
|
|
|
local arr
|
|
|
|
|
arr = new ArrayBox()
|
|
|
|
|
i = 0
|
|
|
|
|
loop(i < ITER) {
|
|
|
|
|
arr.push(i)
|
|
|
|
|
i = i + 1
|
|
|
|
|
}
|
|
|
|
|
print("[array_push] length = " + arr.length())
|
|
|
|
|
|
|
|
|
|
// 3) Mixed arithmetic: simple_add repeated
|
|
|
|
|
local a, b, z
|
|
|
|
|
a = 1
|
|
|
|
|
b = 2
|
|
|
|
|
i = 0
|
|
|
|
|
loop(i < ITER) {
|
|
|
|
|
z = a + b
|
|
|
|
|
a = a + 1
|
|
|
|
|
b = b + 1
|
|
|
|
|
i = i + 1
|
|
|
|
|
}
|
|
|
|
|
print("[simple_add_loop] final z = " + z)
|
|
|
|
|
|
|
|
|
|
print("\nDone.")
|
|
|
|
|
return 0
|