Cast to number

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
for (let i = 0; i < 1000; i++) {
	Number(100);
	Number("100");
}
ready

Revisions

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