diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 97e170c1..12cb462e 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -2376,11 +2376,14 @@ let BENCHMARKS = [ ], tags: ["default", "js", "Generators"], }), - new DefaultBenchmark({ + new AsyncBenchmark({ name: "js-tokens", files: [ "./generators/js-tokens.js", ], + preload: { + SOURCE_CODE: "./generators/js-tokens.js", + }, tags: ["default", "js", "Generators"], }), new DefaultBenchmark({ diff --git a/generators/js-tokens.js b/generators/js-tokens.js index 8385109c..e0b9d327 100644 --- a/generators/js-tokens.js +++ b/generators/js-tokens.js @@ -410,7 +410,6 @@ function jsTokensWrapperFunction() { }; }; -const jsTokensSourceCode = jsTokensWrapperFunction.toString(); const jsxSourceCode = ` function Comment(props) { @@ -437,11 +436,20 @@ function Comment(props) { const jsTokens = jsTokensWrapperFunction(); class Benchmark { + EXPECTED_TOKEN_COUNT = 121975; + + tokenCount = 0; + jsTokensSourceCode = ""; + + async init() { + this.jsTokensSourceCode = await JetStream.getString(JetStream.preload.SOURCE_CODE); + } + runIteration() { this.tokenCount = 0; for (var i = 0; i < 25; i++) { - for (const token of jsTokens(jsTokensSourceCode)) + for (const token of jsTokens(this.jsTokensSourceCode)) this.tokenCount++; } @@ -452,7 +460,7 @@ class Benchmark { } validate(iterations) { - if (this.tokenCount !== 113975) - throw new Error(`this.tokenCount of ${this.tokenCount} is invalid!`); + if (this.tokenCount !== this.EXPECTED_TOKEN_COUNT) + throw new Error(`Expected this.tokenCount of ${this.EXPECTED_TOKEN_COUNT}, but got ${this.tokenCount}!`); } }