26 lines
580 B
JavaScript
26 lines
580 B
JavaScript
var { performance } = require('perf_hooks');
|
|
const timeit = (fun, number=1,prepare=()=>null)=>{
|
|
let time=0
|
|
for(let _=0; _<number;_++){
|
|
// console.log(_)
|
|
prepare()
|
|
const startTime = performance.now();
|
|
fun()
|
|
const endTime = performance.now();
|
|
// console.log(endTime-startTime)
|
|
time+=endTime-startTime;
|
|
}
|
|
|
|
return time
|
|
}
|
|
|
|
|
|
|
|
//inline caches
|
|
function load(a){
|
|
return a.key;
|
|
}
|
|
const o = {key:Math.random()}
|
|
for (let i=0; i<10000; i++){
|
|
console.log(i+","+timeit(()=>load(o), 1, ()=>o.key = Math.random() ))
|
|
} |