Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
16 changes: 12 additions & 4 deletions generators/js-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ function jsTokensWrapperFunction() {
};
};

const jsTokensSourceCode = jsTokensWrapperFunction.toString();
const jsxSourceCode = `

function Comment(props) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we eval or dynamically import this rather than have two copies of the source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote it to reuse js-tokens.js as SOURCE_CODE (requires us to modify the EXPECTED_TOKEN_COUNT whenever we touch it, but thats probably ok)

}

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++;
}

Expand All @@ -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}!`);
}
}
Loading