1
0

memory-profiler.ts 581 B

12345678910111213141516171819202122232425
  1. /* eslint-disable */
  2. /**
  3. * Used to profile peak memory usage for perf optimization purposes
  4. *
  5. * Add it to the index.ts or index-worker.ts:
  6. * ```ts
  7. * import { profileMemory } from './memory-profiler';
  8. *
  9. * profileMemory();
  10. * ```
  11. */
  12. export function profileMemory() {
  13. let max = 0;
  14. setInterval(() => {
  15. const rss = process.memoryUsage().rss;
  16. if (max < rss) {
  17. max = rss;
  18. console.log(`Peak: ${inMb(max)}`);
  19. }
  20. }, 500);
  21. }
  22. function inMb(bytes: number) {
  23. return `${Math.round((bytes / 1024 / 1024) * 100) / 100}MB;`;
  24. }