Skip to content
Merged
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
13 changes: 12 additions & 1 deletion scripts/perf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const jmespath = require('../dist/lib');
const jmespath = require('../dist/lib/src');
const { Bench } = require('tinybench');

async function runBenchmarks() {
Expand All @@ -14,6 +14,7 @@ async function runBenchmarks() {
time: 1000,
});

// Baseline parsing benchmarks
bench
.add('Parser#single_expr', () => {
jmespath.compile('foo');
Expand All @@ -33,6 +34,16 @@ async function runBenchmarks() {
})
.add('Parser#basic_list_projection', () => {
jmespath.compile('foo[*].bar');
})
// Additional lexer-heavy benchmarks
.add('Lexer#common_identifiers', () => {
jmespath.compile('foo.bar.baz.qux.foo.bar.baz.qux');
})
.add('Lexer#mixed_tokens', () => {
jmespath.compile('items[?price > `100`].name');
})
.add('Lexer#function_calls', () => {
jmespath.compile('sort_by(items, &price).name');
});

await bench.run();
Expand Down
6 changes: 2 additions & 4 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ class TokenParser {
}

private loadTokens(expression: string, options: Options): void {
this.tokens = [
...Lexer.tokenize(expression, options),
{ type: Token.TOK_EOF, value: '', start: expression.length },
];
this.tokens = Lexer.tokenize(expression, options);
this.tokens.push({ type: Token.TOK_EOF, value: '', start: expression.length });
}

expression(rbp: number): ExpressionNode {
Expand Down