Skip to content

Commit

Permalink
perf: better performance tests to compare with latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Dec 12, 2023
1 parent 2df6e26 commit 2dd696c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
19 changes: 13 additions & 6 deletions performance/index.node.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { performance } from "perf_hooks";
import { readFileSync } from "fs";
import JSONParser from "../dist/mjs/jsonparse.mjs";
import { JSONParser as LatestsJSONParser } from "@streamparser/json";
import { JSONParser as CurrentJSONParser } from "../packages/plainjs/dist/mjs/index.js";

function repeat(str, number) {
return Array(number).fill(str).join("");
Expand Down Expand Up @@ -53,10 +54,16 @@ console.log("===========");
benchmark(`${Array(100000).fill("9").join("")}`);

function benchmark(jsonStr) {
const jsonparser = new JSONParser();
const latestJsonparser = new LatestsJSONParser({ separator: '' });
latestJsonparser.onValue = () => {};
const currentJsonparser = new CurrentJSONParser({ separator: '' });
currentJsonparser.onValue = () => {};

const start = performance.now();
jsonparser.write(jsonStr);
const end = performance.now();
console.log(`Time: ${end - start} ms.`);
let start = performance.now();
latestJsonparser.write(jsonStr);
const latestTime = performance.now() - start;
start = performance.now();
currentJsonparser.write(jsonStr);
const currentTime = performance.now() - start;
console.log(`Latests Time: ${latestTime} ms. Current Time: ${currentTime} ms. Diff: ${latestTime / currentTime}`);
}
34 changes: 26 additions & 8 deletions performance/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions performance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@streamparser/json": "^0.0.17",
"benchmark": "^2.1.4",
"jsonparse": "^1.3.1"
}
Expand Down

0 comments on commit 2dd696c

Please sign in to comment.