Testing loops

Benchmark created on


Preparation HTML

<script>
function withSlice(arr) {
 return arr.reduce((a, c, i) => {
  arr.slice(i+1, arr.length).forEach((item) => 
  {
   if (c !== item) a.push(`${c}-${item}`);
  });
  return a;
 }, []);
}

function withoutSlice(arr) {
	return arr.reduce((a, c, i) => {
	 arr.forEach((item) => {
		if (c !== item) a.push(`${c}-${item}`);
	 });
	 return a;
    }, []);
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
With slice
withSlice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]);
ready
Nested loops
withoutSlice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]);
ready

Revisions

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