Skip to content

Instantly share code, notes, and snippets.

View matsnow's full-sized avatar

matsnow matsnow

View GitHub Profile
@matsnow
matsnow / forEach_vs_map.js
Created January 21, 2018 15:33
Compare the throughput of Array.forEach and Array.map
const { performance } = require('perf_hooks');
const times = 1000;
const formatter = (num) => Math.floor(num * 100) / 100;
const benchmark = (fn) => {
performance.mark('A');
fn.call()
performance.mark('B');
performance.measure('A to B', 'A', 'B');