Oh My Gauge!
time Javascript operations
const Gauge Benchmark = ;
Gauge
- Create a gauge instance with the results reporting function.
- Wrap a function with the gauge. It will return a function that measures the operation, reports it, and returns the given functions' return value.
A gauge takes in a function
const Gauge = Gauge;const gauge = console;// ^ ^ ^// Milliseconds String report-method const myObj = name: 'My Obj' { return thisname; }; myObjsayName = ;
Benchmark
Benchmark compares between multiple operations. It also scrambles the order so running it multiple times can yield more reliable results.
const Benchmark = ; const benchmark = ; // console.log with default format-- OR --const benchmark = sendMetricsToServer // override the default console.log callback `Method: , Time: ` // override default formatter; ; // Use a map, maps are funconst things = ;things;things;things; ;
This is a classic optimisation example
const Benchmark = const benchmark = const numbers = Array const tests = const option1 = tests const option2 = tests
output |
---|
Option 1: A neat one liner took 1084ms Option 2: A one loop reducer took 553ms |