opencode/packages/codemode-rust/bench/variants/bench-array-callbacks.js
Sebastian 85ffd4dc70 test(codemode): add perturbed variants and a plugin-event benchmark
Each bench program gets an equivalent, differently written variant in
bench/variants/, run next to its original on both implementations, with the
variant / original ratio per side. A plugin-event benchmark runs the
conformance reducer with a git.status tool as a 226-byte and a 3 KB source.
RESULTS.md labels medians, mins and means, computes speed-ups from medians
only, and notes that the reference tools validate through Effect Schema.
2026-11-18 18:53:57 +01:00

19 lines
510 B
JavaScript

const COUNT = 5e4
const values = Array.from({ length: COUNT }, function (unused, idx) {
return (7919 * idx) % COUNT
})
function twice(v) {
return v + v
}
const kept = values.map(twice).filter(function (v) {
return v % 3 != 0
})
const sum = kept.reduce(function (acc, v) {
return acc + v
}, 0)
function ascending(left, right) {
return left < right ? -1 : left > right ? 1 : 0
}
const ordered = kept.slice(0, 2e4).sort(ascending)
const last = ordered.length - 1
return [sum, ordered[0], ordered[last]]