Skip to content
Closed
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
27 changes: 15 additions & 12 deletions test/perf.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var parser = require("./main");

const parser = require("./main");
const os = require("os");
const cpus = os.cpus();
const cpuId = cpus.length + "@" + cpus[0].speed + 'Mhz';
describe("Performance tests", function() {
var code = `
<?php
Expand All @@ -15,6 +17,7 @@ describe("Performance tests", function() {
}
`;

console.log("Testing perfs on " + cpuId + " / " + cpus[0].model);
it("tokenizer", function() {
var reader = new parser();
var tokSize = reader.tokenGetAll(code).length;
Expand All @@ -34,9 +37,9 @@ describe("Performance tests", function() {
speed = speed / 1000;
if (speed > 1000) {
speed = speed / 1000;
speed = Math.round(speed * 100) / 100 + "M";
speed = Math.round(speed * 100) / 100 + "M Tokens";
} else {
speed = Math.round(speed * 100) / 100 + "K";
speed = Math.round(speed * 100) / 100 + "K Tokens";
}
}
console.log(" + Tokens speed => " + speed + "/sec");
Expand All @@ -48,12 +51,12 @@ describe("Performance tests", function() {
speed = speed / 1024;
if (speed > 1024) {
speed = speed / 1024;
speed = Math.round(speed * 100) / 100 + "M";
speed = Math.round(speed * 100) / 100 + " Mb";
} else {
speed = Math.round(speed * 100) / 100 + "K";
speed = Math.round(speed * 100) / 100 + " Kb";
}
}
console.log(" + Reading speed => " + speed + "/sec");
console.log(" + Reading bandwidth => " + speed + "/sec");
});

it("parser", function() {
Expand Down Expand Up @@ -93,9 +96,9 @@ describe("Performance tests", function() {
speed = speed / 1000;
if (speed > 1000) {
speed = speed / 1000;
speed = Math.round(speed * 100) / 100 + "M";
speed = Math.round(speed * 100) / 100 + "M Nodes";
} else {
speed = Math.round(speed * 100) / 100 + "K";
speed = Math.round(speed * 100) / 100 + "K Nodes";
}
}
console.log(" + Nodes speed => " + speed + "/sec");
Expand All @@ -107,11 +110,11 @@ describe("Performance tests", function() {
speed = speed / 1024;
if (speed > 1024) {
speed = speed / 1024;
speed = Math.round(speed * 100) / 100 + "M";
speed = Math.round(speed * 100) / 100 + " Mb";
} else {
speed = Math.round(speed * 100) / 100 + "K";
speed = Math.round(speed * 100) / 100 + " Kb";
}
}
console.log(" + Overall speed => " + speed + "/sec");
console.log(" + Overall bandwidth => " + speed + "/sec");
});
});
Empty file added test/perf/class.php
Empty file.
21 changes: 21 additions & 0 deletions test/perf/statistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"threshold": {
"tokens": 0.95,
"nodes": 0.9
},
"versions": {
"3.0.0-prerelease.9": {
"12@3674Mhz": {
"model": "AMD Ryzen 5 2600 Six-Core Processor",
"files": {
"class.php": {
"tokensPerSec": 29091000,
"tokenBandwidth": 61984000,
"nodesPerSec": 7731000,
"parseBandwidth": 20513000
}
}
}
}
}
}