Skip to content
Myr

measure.js

This file

Path

__performance_tests__/measure.js

20 lines · 499 bytes · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 21ad96b point at it.

Merge pull request #197 from 0xflotus/patch-1Michel Weststratebefore adoption21ad96b

lines 1–20why, one step back
1"use strict"
23function measureTime(setup, fn) {4 if (!fn) {5 fn = setup6 setup = () => {}7 }8 const args = setup()9 global.gc && global.gc()10 const startTime = Date.now()11 fn(args)12 const endTime = Date.now()13 return endTime - startTime14}1516export function measure(name, setup, fn) {17 const times = [...Array(5)].map(() => measureTime(setup, fn))18 const medianTime = times.sort()[Math.round(times.length / 2)]19 console.log(`${name}: ${medianTime}ms`)20}