• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
10goog.module('protobuf.benchmark.codeSize.codeSizeBase');
11
12
13/**
14 * Ensures that the array iterator polyfill is live.
15 * @return {string}
16 */
17function useArrayIterator() {
18  let a = [];
19  let s = '';
20  for (let value of a) {
21    s += value;
22  }
23  return s;
24}
25
26/**
27 * Ensures that the symbol iterator polyfill is live.
28 * @return {string}
29 */
30function useSymbolIterator() {
31  /**
32   * @implements {Iterable}
33   */
34  class Foo {
35    /** @return {!Iterator} */
36    [Symbol.iterator]() {}
37  }
38
39  let foo = new Foo();
40  let s = '';
41  for (let value of foo) {
42    s += value;
43  }
44  return s;
45}
46
47/**
48 * Ensures certain base libs are live so we can have an apples to apples
49 * comparison for code size of different implementations
50 */
51function ensureCommonBaseLine() {
52  goog.global['__hiddenTest'] += useArrayIterator();
53  goog.global['__hiddenTest'] += useSymbolIterator();
54}
55
56
57exports = {ensureCommonBaseLine};
58