profile.benchmark.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Benchmarks allow us to make changes and evaluate performance before the code gets shipped to production.
  2. // They can be used to make performance improvements or to test impact of newly added functionality.
  3. // Run with: yarn run ts-node --project ./config/tsconfig.benchmark.json -r tsconfig-paths/register static/app/utils/profiling/profile/profile.benchmark.ts
  4. import benchmarkjs from 'benchmark';
  5. import {initializeLocale} from 'sentry/bootstrap/initializeLocale';
  6. import eventedTrace from './formats/android/trace.json';
  7. import sampledTrace from './formats/ios/trace.json';
  8. import jsSelfProfileTrace from './formats/jsSelfProfile/trace.json';
  9. import typescriptTrace from './formats/typescript/trace.json';
  10. import {importProfile} from './importProfile';
  11. // This logs an error which is annoying to see in the outputs
  12. initializeLocale({} as any);
  13. // We dont compare benchmark results, as we are testing a single version of the code, so we run this as a baseline,
  14. // store the results somewhere locally and then compare the results with the new version of our code.
  15. function benchmark(name: string, callback: () => void) {
  16. const suite = new benchmarkjs.Suite();
  17. suite
  18. .add(name, callback)
  19. .on('cycle', event => {
  20. // well, we need to see the results somewhere
  21. // eslint-disable-next-line
  22. console.log(event.target.toString());
  23. })
  24. .on('error', event => {
  25. // If something goes wrong, fail early
  26. throw event;
  27. });
  28. suite.run({async: true});
  29. }
  30. benchmark('typescript', () => importProfile(typescriptTrace as any, ''));
  31. benchmark('js self profile', () => importProfile(jsSelfProfileTrace as any, ''));
  32. benchmark('evented profile', () => importProfile(eventedTrace as any, ''));
  33. benchmark('sampled profile', () => importProfile(sampledTrace as any, ''));