mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
// Per-run setup cost: making a runtime, and running a trivial program end to end, in microseconds.
|
|
// Usage: bun run script/setup.ts [--iterations N]
|
|
|
|
import { Effect } from "effect"
|
|
import { CodeMode } from "../src/index.js"
|
|
import { Interpreter } from "../src/language/runtime/interpreter.js"
|
|
import { createBuiltins } from "../src/language/runtime/intrinsics.js"
|
|
|
|
const index = process.argv.indexOf("--iterations")
|
|
const iterations = index === -1 ? 2000 : Number(process.argv[index + 1])
|
|
|
|
const runtime = CodeMode.make({ tools: {} })
|
|
|
|
const measure = async (name: string, work: () => unknown) => {
|
|
for (let at = 0; at < 200; at++) await work()
|
|
const times: Array<number> = []
|
|
for (let at = 0; at < iterations; at++) {
|
|
const start = performance.now()
|
|
await work()
|
|
times.push(performance.now() - start)
|
|
}
|
|
times.sort((a, b) => a - b)
|
|
const micros = (ms: number) => `${(ms * 1000).toFixed(0).padStart(5)} µs`
|
|
console.log(
|
|
`${name.padEnd(24)} median ${micros(times[times.length >> 1]!)} p10 ${micros(times[Math.floor(times.length / 10)]!)}`,
|
|
)
|
|
}
|
|
|
|
await measure("runtime", () => new Interpreter({ builtins: createBuiltins() }))
|
|
await measure("trivial program", () => Effect.runPromise(runtime.execute("return 1")))
|