code_size_base.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @fileoverview Ensures types are live that would be live in a typical g3
  3. * JS program.
  4. *
  5. * Making certain constructs live ensures that we compare against the same
  6. * baseline for all code size benchmarks. This increases the size
  7. * of our benchmarks, but note that this size in a regular app would be
  8. * attributes to other places.
  9. */
  10. goog.module('protobuf.benchmark.codeSize.codeSizeBase');
  11. /**
  12. * Ensures that the array iterator polyfill is live.
  13. * @return {string}
  14. */
  15. function useArrayIterator() {
  16. let a = [];
  17. let s = '';
  18. for (let value of a) {
  19. s += value;
  20. }
  21. return s;
  22. }
  23. /**
  24. * Ensures that the symbol iterator polyfill is live.
  25. * @return {string}
  26. */
  27. function useSymbolIterator() {
  28. /**
  29. * @implements {Iterable}
  30. */
  31. class Foo {
  32. /** @return {!Iterator} */
  33. [Symbol.iterator]() {}
  34. }
  35. let foo = new Foo();
  36. let s = '';
  37. for (let value of foo) {
  38. s += value;
  39. }
  40. return s;
  41. }
  42. /**
  43. * Ensures certain base libs are live so we can have an apples to apples
  44. * comparison for code size of different implementations
  45. */
  46. function ensureCommonBaseLine() {
  47. goog.global['__hiddenTest'] += useArrayIterator();
  48. goog.global['__hiddenTest'] += useSymbolIterator();
  49. }
  50. exports = {ensureCommonBaseLine};