Skip to content

Commit 6defb43

Browse files
author
MesTTo
committed
feat: benchmark + RESULTS, README status, runnable examples
1 parent 4b727e6 commit 6defb43

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ Performance stays pure TypeScript: staging/partial-evaluation of the eval loop,
1414

1515
## Status
1616

17-
Pre-implementation. The full, self-contained implementation plan lives in [`docs/superpowers/plans/`](docs/superpowers/plans/).
17+
The core interpreter is implemented and **passes all 270 assertions** of Hyperon's oracle corpus — the full dependent-type tier (GADTs, dependent types, types-as-propositions), spaces and mutable state, nondeterminism, grounded operations, and documentation — matching the machine-checked LeaTTa result exactly. Pure TypeScript: it builds to a ~72 KB ESM bundle, runs in Node and the browser, with no native addon and no WASM.
18+
19+
```bash
20+
pnpm install
21+
pnpm build
22+
pnpm test # 270/270 Hyperon oracle gate + unit/property tests
23+
node packages/node/dist/cli.js examples/factorial.metta
24+
```
25+
26+
Packages: [`@metta-ts/core`](packages/core) (the interpreter, zero platform deps), [`@metta-ts/node`](packages/node) (CLI + file `import!`), [`@metta-ts/browser`](packages/browser) (web entry + in-memory VFS). The full implementation plan and the binding spec live in [`docs/superpowers/`](docs/superpowers/).
1827

1928
## Provenance
2029

examples/factorial.metta

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; Factorial via the minimal `unify` instruction (single rule, no divergence).
2+
; `unify` and the arithmetic ops come from the standard prelude.
3+
(= (fact $n) (unify $n 0 1 (* $n (fact (- $n 1)))))
4+
5+
!(fact 5) ; [120]
6+
!(fact 10) ; [3628800]

examples/families.metta

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; A tiny knowledge base queried with `match` over the &self space, plus nondeterminism.
2+
(Parent Tom Bob)
3+
(Parent Bob Ann)
4+
(Parent Bob Pat)
5+
6+
; Grandparent via a conjunctive match.
7+
(= (grandparent $g $c)
8+
(match &self (, (Parent $g $p) (Parent $p $c)) ($g $c)))
9+
10+
!(match &self (Parent Bob $child) $child) ; [Bob's children: Ann, Pat]
11+
!(grandparent Tom $who) ; [(Tom Ann) (Tom Pat)]

packages/node/bench/RESULTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Benchmark results
2+
3+
Pure TypeScript, no native addon, no WASM. Node v22, single core. Run: `pnpm --filter @metta-ts/core build && node packages/node/bench/bench.mjs`.
4+
5+
| benchmark | time |
6+
|-----------|------|
7+
| stdlib parse + load + `(+ 1 2)` (prelude cached) | ~0.07 ms |
8+
| `fib(18)` naive double-recursion (~10.9k calls) | ~185 ms |
9+
| full 270-assertion Hyperon oracle (22 files) | ~134 ms |
10+
11+
These are correctness-first numbers (a faithful tree-walker; `buildEnv` is rebuilt per query, no memoization). The Phase-15 roadmap (staging/partial-evaluation, a flat interned atom core, a bytecode VM, a `mnemonist` AtomSpace index) targets the hot paths these expose, each gated by the 270/270 oracle so speed never costs correctness.

packages/node/bench/bench.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Performance benchmark for the MeTTa TS interpreter (pure TypeScript, no native, no WASM).
2+
// Run after building core: `node packages/node/bench/bench.mjs`
3+
import { runProgram } from "../../core/dist/index.js";
4+
import { readFileSync, readdirSync } from "node:fs";
5+
import { resolve } from "node:path";
6+
7+
function bench(name, f, iters = 1) {
8+
for (let i = 0; i < 3; i++) f(); // warmup
9+
const t = performance.now();
10+
for (let i = 0; i < iters; i++) f();
11+
const ms = (performance.now() - t) / iters;
12+
console.log(name.padEnd(40), ms.toFixed(2) + " ms");
13+
}
14+
15+
bench("stdlib parse+load + (+ 1 2)", () => runProgram("!(+ 1 2)"), 50);
16+
17+
const fib =
18+
"(= (fib $n) (unify $n 0 0 (unify $n 1 1 (+ (fib (- $n 1)) (fib (- $n 2))))))\n!(fib 18)";
19+
bench("fib(18) naive double-recursion", () => runProgram(fib), 5);
20+
21+
const CORPUS = resolve(process.cwd(), "corpus");
22+
const files = readdirSync(CORPUS).filter((f) => f.endsWith(".metta") && f !== "c2_spaces_kb.metta");
23+
bench("full 270-assertion oracle (22 files)", () => {
24+
for (const f of files) runProgram(readFileSync(resolve(CORPUS, f), "utf8"));
25+
});
26+
27+
console.log("\nnode " + process.version + " | pure TypeScript, no native, no WASM");

0 commit comments

Comments
 (0)