X (v2)

Revision 2 of this benchmark created on


Setup

let x = { next: undefined };
for (let i = 0; i < 10000; i++) {
    x = { next: x, ref:  new WeakRef(x) };
}
let x2 = { next: undefined };
let x2holder = [x2];
for (let i = 0; i < 10000; i++) {
    const x2Item = { next: new WeakRef(x2) };
    x2holder.push(x2Item);
    x2 = x2Item;
}

Test runner

Ready to run.

Testing in
TestOps/sec
ref
    let y = x;
    for (let i = 0; i < 10000; i++) {
        y = y.next;
    }
ready
weak
    let y = x;
    for (let i = 0; i < 10000; i++) {
        y = y.ref.deref();
    }
ready

Revisions

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