You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varonIdle=require('on-idle')onIdle(function(){console.log('yay, doing stuff in idle time!')})
render performance act 3
the render loop (on chrome)
microtask queue resolves first
setTimeout() timers resolve second
requestAnimationFrame() resolves third
paints and reflows
requestIdleCallback() resolves last
npm install nanotask
varnanotask=require('nanotask')varqueue=nanotask()queue(function(){console.log('yay, hooking into mutation observers')})queue(function(){console.log('but not promises b/c try...catch')})
trace logging
b/c measuring = knowing
measuring things!
// create unique namesvarstartName='start-my-mark-'+window.performance.now()varendName='end-my-mark-'+window.performance.now()varmeasureName='my-mark-'+window.performance.now()// create marks around an operationwindow.performance.mark(startName)vari=1000;while(--i)console.log(i)window.performance.mark(endName)window.requestIdleCallback(function(){// measure the time between markswindow.performance.measure(measureName,startName,endName)varmeasure=window.performance.getEntriesByName(measureName)[0]console.log(measure.duration)// clear all entries by namewindow.performance.clearMarks(startName)window.performance.clearMarks(endName)window.performance.clearMeasures(measureName)})
npm install nanotiming
varnanotiming=require('nanotiming')vartiming=nanotiming('my-cool-timing')vari=1000;while(--i)console.log(i)timing(function(measure,name){console.log(name+' took '+measure.duration+'ms')})
varassert=require('assert')functionmyFunction(a,b){assert.equal(typeofa,'string','my-function: a should be type string')assert.equal(typeofb,'object','my-function: b should be type object')assert.equal(typeofwindow,'object','my-function: window should exist in the context')}