Skip to content

Commit 26b9a84

Browse files
committed
Add implementation that just calls readline
1 parent 32e08e0 commit 26b9a84

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

extensions/ql-vscode/test/benchmarks/jsonl-reader.bench.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { readFile } from "fs-extra";
22
import { readJsonlFile, readJsonlFile2 } from "../../src/common/jsonl-reader";
33
import { performance } from "perf_hooks";
44
import { join } from "path";
5+
import { createReadStream } from "fs";
6+
import { createInterface } from "readline";
57

68
/** An "obviously correct" implementation to test against. */
79
async function readJsonlReferenceImpl<T>(
@@ -19,6 +21,18 @@ async function readJsonlReferenceImpl<T>(
1921
}
2022
}
2123

24+
async function justReadline(
25+
path: string,
26+
handler: (value: unknown) => Promise<void>,
27+
) {
28+
const stream = createReadStream(path, "utf8");
29+
const rl = createInterface(stream);
30+
31+
for await (const line of rl) {
32+
await handler(line);
33+
}
34+
}
35+
2236
type ParserFn = (
2337
text: string,
2438
callback: (v: unknown) => Promise<void>,
@@ -28,6 +42,7 @@ const parsers: Record<string, ParserFn> = {
2842
readJsonlReferenceImpl,
2943
readJsonlFile,
3044
readJsonlFile2,
45+
justReadline,
3146
};
3247

3348
async function main() {

0 commit comments

Comments
 (0)