○
Planned This feature is planned but not yet implemented.
Parked on binding-field access in ARGUMENT position, and no longer on `~`.
Code
// REAL Interpreter Benchmark
// Tests the FULL pipeline: parse Koru flow string → execute → return result
// Uses a realistic multi-step flow with continuations
~import std/runtime
~import std/interpreter
const std = @import("std");
// ============================================================================
// Events that the flow will dispatch to
// ============================================================================
~pub tor compute { a: string, b: string, op: string }
| result string
| error string
~proc compute|zig {
const a_val = std.fmt.parseInt(i64, a, 10) catch 0;
const b_val = std.fmt.parseInt(i64, b, 10) catch 0;
const value = if (std.mem.eql(u8, op, "add"))
a_val + b_val
else if (std.mem.eql(u8, op, "mul"))
a_val * b_val
else if (std.mem.eql(u8, op, "sub"))
a_val - b_val
else
0;
var buf: [32]u8 = undefined;
const result_str = std.fmt.bufPrint(&buf, "{d}", .{value}) catch "0";
return .{ .result = result_str };
}
~pub tor print-result { value: string }
~proc print-result|zig {
std.debug.print("Result: {s}\n", .{value});
}
// Register events for runtime dispatch
~std/runtime:register(scope: "bench") {
compute
print-result
}
// ============================================================================
// The flow we'll parse and execute at runtime
// This is a REAL flow with continuations
// ============================================================================
const FLOW_SOURCE =
\\compute(a: "42", b: "17", op: "add")
\\| result r |> print-result(r.value)
\\| error e |> print-result(value: e.message)
;
~import std/io
// ============================================================================
// Benchmark: Parse and execute the flow
// ============================================================================
~std/interpreter:run(source: FLOW_SOURCE, dispatcher: dispatch_bench)
| result r |> std/io:print.ln("Success: branch {{ r.value.branch:s }}")
| exhausted e |> std/io:print.ln("Exhausted: {{ e.last_event:s }}")
| parse-error e |> std/io:print.ln("Error: {{ e.message:s }}")
| validation-error e |> std/io:print.ln("Error: {{ e:s }}")
| dispatch-error e |> std/io:print.ln("Error: {{ e.message:s }}")
Supporting Files
-- REAL LuaJIT Interpreter Benchmark
-- Tests: parse Lua source → execute → return result
-- Using loadstring() to parse and execute code at runtime
-- Equivalent computation: 42 + 17 = 59
local ITERATIONS = 10000
-- The source code we'll parse and execute each iteration
-- This is equivalent to Koru's ~compute(a: 42, b: 17, op: "add")
local code = "return 42 + 17"
print("")
print("╔══════════════════════════════════════════════════════════════╗")
print("║ LuaJIT loadstring() Benchmark: Parse + Execute ║")
print("╚══════════════════════════════════════════════════════════════╝")
print("")
local start = os.clock()
local sum = 0
for i = 1, ITERATIONS do
-- Parse and execute Lua source code each iteration
local fn = loadstring(code)
sum = sum + fn()
end
local elapsed = os.clock() - start
local elapsed_ms = elapsed * 1000
local ops_per_sec = ITERATIONS / elapsed
print("LuaJIT loadstring():")
print(string.format(" Iterations: %d", ITERATIONS))
print(string.format(" Time: %.2fms", elapsed_ms))
print(string.format(" Throughput: %d parse+exec/sec", math.floor(ops_per_sec)))
print(string.format(" Sum: %d (expected: %d)", sum, ITERATIONS * 59))
# REAL Python Interpreter Benchmark
# Tests: parse Python source → execute → return result
# Using eval() to parse and execute code at runtime
# Equivalent computation: 42 + 17 = 59
import time
ITERATIONS = 10_000
# The source code we'll parse and execute each iteration
# This is equivalent to Koru's ~compute(a: 42, b: 17, op: "add")
code = "42 + 17"
print("")
print("╔══════════════════════════════════════════════════════════════╗")
print("║ Python eval() Benchmark: Parse + Execute ║")
print("╚══════════════════════════════════════════════════════════════╝")
print("")
start = time.perf_counter_ns()
total = 0
for i in range(ITERATIONS):
# Parse and execute Python source code each iteration
total += eval(code)
end = time.perf_counter_ns()
elapsed_ns = end - start
elapsed_ms = elapsed_ns / 1_000_000
ops_per_sec = ITERATIONS / (elapsed_ns / 1_000_000_000)
print("Python eval():")
print(f" Iterations: {ITERATIONS}")
print(f" Time: {elapsed_ms:.2f}ms")
print(f" Throughput: {int(ops_per_sec)} parse+exec/sec")
print(f" Sum: {total} (expected: {ITERATIONS * 59})")
Expected output
Result: 59
Success: branch
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "bench", source: compute
print-result)
flow ~run click a branch to expand · @labels scroll to their anchor
run (source: FLOW_SOURCE, dispatcher: dispatch_bench)
Test Configuration
MUST_RUN