Skip to main content
100%

Gist c0ec6bb768fd2672307b0807e4ee46fb

✓ Published0🌍 Public
MMAKIO135
Last edited May 5, 2017
Created on May 5, 2017

This example benchmarks four JavaScript loop styles—a standard `for` loop, a reversed `for` loop, a `for…of` loop, and `forEach`—on a fixed array of ten numbers. It measures execution time by repeating each loop a thousand times via `performance.now()` timestamps, accumulating the total milliseconds. The code defines each loop as a separate function and calls them through a `test` helper, logging the sum to the console. The comparison uses a simple in-memory data array, with no external libraries, focusing on raw loop performance in a JavaScript environment.

AI-generated description

Similar vizzes