addition perf (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
number
const a = Math.random() * 1e3;
const b = Math.random() * 1e3;
const c = a + b;
ready
boxed
class Instant {
	#n;
	constructor(n) {
		this.#n = n;
	}
	valueOf() {
		return this.#n;
	}
	plus(other) {
		return new Instant(this.valueOf() + other.valueOf());
	}
}
class Duration {
	#n;
	constructor(n) {
		this.#n = n;
	}
	valueOf() {
		return this.#n;
	}
}

const a = new Instant(Math.random() * 1e3);
const b = new Duration(Math.random() * 1e3);
const c = a.plus(b);
ready
branded
const Time = {
    Duration: {
        fromMillis: (millis) => millis
    },
    Milliseconds: {
        of: (value) => value
    },
    StreamTime: {
        fromMillis: (millis) => millis,
        addDuration: (time, duration) => {
            return (time + duration);
        }
    }
};
const a = Time.StreamTime.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const b = Time.Duration.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const c = Time.StreamTime.addDuration(a, b);
ready
branded: arithmetic + no rewrap
const Time = {
    Duration: {
        fromMillis: (millis) => millis
    },
    Milliseconds: {
        of: (value) => value
    },
    StreamTime: {
        fromMillis: (millis) => millis,
        addDuration: (time, duration) => {
            return (time + duration);
        }
    }
};
const a = Time.StreamTime.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const b = Time.Duration.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const c = Time.StreamTime.fromMillis(a + b);
ready
branded: arithmetic + rewrap
const Time = {
    Duration: {
        fromMillis: (millis) => millis
    },
    Milliseconds: {
        of: (value) => value
    },
    StreamTime: {
        fromMillis: (millis) => millis,
        addDuration: (time, duration) => {
            return (time + duration);
        }
    }
};
const a = Time.StreamTime.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const b = Time.Duration.fromMillis(Time.Milliseconds.of(Math.random() * 1e3));
const c = a + b; // number
ready

Revisions

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