Skip to content

Instantly share code, notes, and snippets.

@aquapi
Created June 28, 2025 16:45
Show Gist options
  • Select an option

  • Save aquapi/0ea995416b86c850088330107317be31 to your computer and use it in GitHub Desktop.

Select an option

Save aquapi/0ea995416b86c850088330107317be31 to your computer and use it in GitHub Desktop.
import { summary, bench, run, do_not_optimize } from 'mitata';
bench('noop', () => { });
bench('noop', () => { });
bench('noop', () => { });
summary(() => {
{
const fn = (a: number, b: number) => a * 2 + b + Math.random();
do_not_optimize(fn);
bench('Arrow', function* () {
yield {
[0]: Math.random,
[1]: Math.random,
bench: (a: number, b: number) => {
do_not_optimize(fn(a, b));
}
}
});
}
{
function fn(a: number, b: number) { return a * 2 + b + Math.random(); }
do_not_optimize(fn);
bench('Func', function* () {
yield {
[0]: Math.random,
[1]: Math.random,
bench: (a: number, b: number) => {
do_not_optimize(fn(a, b));
}
}
});
}
});
summary(() => {
{
function fn(a: number, b: number) { return a * 2 + b + Math.random(); }
do_not_optimize(fn);
bench('Func', function* () {
yield {
[0]: Math.random,
[1]: Math.random,
bench: (a: number, b: number) => {
do_not_optimize(fn(a, b));
}
}
});
}
{
const fn = (a: number, b: number) => a * 2 + b + Math.random();
do_not_optimize(fn);
bench('Arrow', function* () {
yield {
[0]: Math.random,
[1]: Math.random,
bench: (a: number, b: number) => {
do_not_optimize(fn(a, b));
}
}
});
}
});
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment