Loop Test

Benchmark created on


Setup

const numbers = [
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
53,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
54,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
55,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
56,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
57,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
58,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
59,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
61,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
62,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
63,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
64,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
65,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
66,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
67,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
68,
]

Test runner

Ready to run.

Testing in
TestOps/sec
forEach loop
const distinct = new Set();

numbers.forEach(x => {
	const voyageNo = x;
		
	if (voyageNo || voyageNo === 0) {
		distinct.add(x);
	}
});
ready
for loop
const distinct = new Set();

for (let i = 0; i < numbers.length; i++) {
	const voyageNo = numbers[i];

	if (voyageNo || voyageNo === 0) {
		distinct.add(voyageNo);
	}
}
ready
for in
const distinct = new Set();

for (var key in numbers) {
	const voyageNo = numbers[key];

	if (voyageNo || voyageNo === 0) {
		distinct.add(voyageNo);
	}
}
ready
for of
const distinct = new Set();

for (var value of numbers) {
	const voyageNo = value;

	if (voyageNo || voyageNo === 0) {
		distinct.add(voyageNo);
	}
}
ready
map
const distinct = new Set();

numbers.map(x => {
	const voyageNo = x;

	if (voyageNo || voyageNo === 0) {
		distinct.add(voyageNo);
	}
});
ready
filter
const distinct = new Set();

numbers.filter(x => {
	const voyageNo = x;

	if (voyageNo || voyageNo === 0) {
		distinct.add(voyageNo);
	}
});
ready
reduce
numbers.reduce((distinct, voyageNo) => {
  if (voyageNo || voyageNo === 0) {
    distinct.add(voyageNo);
  }
  
  return distinct;
}, new Set());
ready

Revisions

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