math vs variable creation

Benchmark created on


Description

i % 2 vs creating a variable for it.

Test runner

Ready to run.

Testing in
TestOps/sec
j % 2
let results = 0;
for (let i = 0; i < 10000; i ++) {
	if (i % 2) results++;
	if (i % 2) results++;
	if (i % 2) results++;
}
ready
memo with variable
let results = 0;
for (let i = 0; i < 10000; i ++) {
	const memo = i % 2;
	if (memo) results++;
	if (memo) results++;
	if (memo) results++;
}
ready

Revisions

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