Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.1 KB
Raw Blame
#!/usr/bin/env node
// Feed pipeline-bench fixtures to bare @xterm/headless to separate parser/buffer cost from Orca delivery/scanning/paint.
// Compare with plain-text rate; matching parser throughput places the pipeline gap in Orca layers.
// Usage: node tests/tools/benchmarks/terminal-headless-parse-bench.mjs [--size-mb 10] [--cols 114] [--rows 85] [--scrollback 5000]
import { performance } from 'node:perf_hooks'
import xterm from '@xterm/headless'
import { buildFixture } from './terminal-pipeline-bench.mjs'

const { Terminal } = xterm
const CHUNK = 64 * 1024

function arg(name, fallback) {
  const i = process.argv.indexOf(name)
  return i === -1 ? fallback : Number(process.argv[i + 1])
}

const sizeMb = arg('--size-mb', 10)
const cols = arg('--cols', 114)
const rows = arg('--rows', 85)
const scrollback = arg('--scrollback', 5000)
const targetBytes = Math.floor(sizeMb * 1024 * 1024)

function writeAll(term, data) {
  return new Promise((resolve) => {
    let offset = 0
    const next = () => {
      if (offset >= data.length) {
        resolve()
        return
      }
      const chunk = data.slice(offset, offset + CHUNK)
      offset += CHUNK
      // write callback fires after the chunk is parsed — same "fully parsed"
      // fence semantics as the DSR fence in the pipeline bench.
      term.write(chunk, next)
    }
    next()
  })
}

const FIXTURES = ['ascii-log', 'cjk-emoji', 'agent-tui', 'styles-stress']

console.log(
  `headless xterm ${cols}x${rows} scrollback=${scrollback}, ${sizeMb}MB per fixture (parse-only, no render)`
)
for (const name of FIXTURES) {
  const fixture = buildFixture(name, targetBytes, cols, rows)
  const bytes = Buffer.byteLength(fixture, 'utf8')
  const term = new Terminal({ cols, rows, scrollback, allowProposedApi: true })
  // Warmup primes JIT so the first fixture isn't penalized.
  await writeAll(term, fixture.slice(0, 256 * 1024))
  const start = performance.now()
  await writeAll(term, fixture)
  const ms = performance.now() - start
  console.log(
    `${name.padEnd(15)} ${(bytes / 1024 / 1024 / (ms / 1000)).toFixed(1).padStart(7)} MB/s  (${ms.toFixed(0)}ms)`
  )
  term.dispose()
}