Virtual Call ABI

Benchmark created on


Description

An experiment with the performance of different ABIs for polymorphic code

Setup

function foo(a, add, mul) {
    return mul(add(a, a), a);
}
const add_s = Symbol();
const mul_s = Symbol();
function foo2(a, v) {
    const add = v[add_s];
    const mul = v[mul_s];
    return mul(add(a, a), a);
}

function foo3(a) {
    return a[mul_s](a[add_s](a), a);
}

const v = 12;
const add = function(n, m) { return n + m; }
const mul = function(n, m) { return n * m; }
const proto = { [add_s]: add, [mul_s]: mul };
const vt = Object.create(proto)
class MyNumber extends Number {}
MyNumber.prototype[add_s] = add;
MyNumber.prototype[mul_s] = mul;
const v_number = new Number(v);
const v_mynumber = new MyNumber(v);

Test runner

Ready to run.

Testing in
TestOps/sec
Directly passing functions
foo(v, add, mul)
ready
Via vtable
foo2(v, proto)
ready
Via VTable + hidden class optimization
foo2(v, vt)
ready
As object
foo2(v_number, vt)
ready
As object via own prototype
foo3(v_mynumber)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.