Created
          December 28, 2023 10:57 
        
      - 
      
 - 
        
Save pirey/499264af254e5efb33a0ce53438c19d5 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
pirey created this gist
Dec 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ async function withMeasure<T>(label: string = 'Measurement', fn: () => Promise<T>) { function bytes2MB(bytes: number): number { return bytes / (1024 * 1024) } const pstart = performance.now() const mstart = process.memoryUsage().heapUsed const result = await fn() const mend = process.memoryUsage().heapUsed const mused = mend - mstart const pend = performance.now() const duration = pend - pstart console.log(`${label}: ${duration} milliseconds ${mused} bytes ${bytes2MB(mused)} MB`) console.log(`mStart: ${mstart} mEnd: ${mend} bytes`) console.log(`pStart: ${pstart} pEnd: ${pend} bytes`) console.log('---') return result }