Cast to number (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
with type check
function cast(x) {
	if (typeof x === "string") {
		return Number(x);
	}
	
	return x;
}

for (let i = 0; i < 1000; i++) {
	cast(100);
	cast("100");
}
ready
w/o type check
function cast(x) {
	return Number(x);
}

for (let i = 0; i < 1000; i++) {
	cast(100);
	cast("100");
}
ready

Revisions

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