diff --git a/gulpfile.js b/gulpfile.js
index cf8c1bd..24fd4b2 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -11,10 +11,8 @@ task( "lint", () => [
src( [
"**/.*rc.js",
"packages/**/*.js",
- "test/benchmark/**/*.js",
- "test/benchmark/run",
- "test/impact",
"test/spec/**/*.js",
+ "tools/**/*.js",
"src/*.js",
"rollup.config.js",
"gulpfile.js",
@@ -33,13 +31,6 @@ task( "test", () =>
);
-// Run benchmarks.
-task( "benchmark", () =>
-
- run( "node test/benchmark/run" )
-
-);
-
// Generate the grammar parser.
task( "build:parser", () =>
diff --git a/now.json b/now.json
index 44d7743..4bbad4f 100644
--- a/now.json
+++ b/now.json
@@ -13,8 +13,10 @@
"examples",
"packages",
"test",
+ "tools/benchmark",
"website",
".babelrc.js",
+ "package.json",
"server.js",
"yarn.lock"
]
diff --git a/package.json b/package.json
index 2727b3b..410eb84 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"scripts": {
"lint": "gulp lint",
"spec": "gulp test",
- "benchmark": "gulp benchmark",
+ "benchmark": "benchmark",
"build:parser": "gulp build:parser",
"build:dist": "rollup -c",
"clean": "gulp clean",
diff --git a/server.js b/server.js
index 2210e76..dc23c28 100644
--- a/server.js
+++ b/server.js
@@ -32,7 +32,7 @@ app.set( "view engine", "ejs" );
app.use( logger( "dev" ) );
app.use( express.static( path( "website" ) ) );
-app.use( "/benchmark", express.static( path( "test", "benchmark" ) ) );
+app.use( "/benchmark", express.static( path( "tools", "benchmark" ) ) );
app.use( "/examples", express.static( path( "examples" ) ) );
app.use( layout() );
@@ -133,7 +133,7 @@ babelOptions.exclude = "node_modules/**";
babelOptions.runtimeHelpers = true;
[
- { name: "benchmark", input: "test/benchmark/**/*.js" },
+ { name: "benchmark", input: "tools/benchmark/browser.js" },
{ name: "spec", input: "test/spec/**/*.js" },
{ name: "peg", input: "packages/pegjs/lib/peg.js", format: "umd" },
@@ -219,6 +219,7 @@ babelOptions.runtimeHelpers = true;
include: [
"packages/**",
"test/**",
+ "tools/benchmark/**"
],
},
diff --git a/test/benchmark/benchmarks.js b/tools/benchmark/benchmarks.js
similarity index 99%
rename from test/benchmark/benchmarks.js
rename to tools/benchmark/benchmarks.js
index 0ed0d2f..4a67732 100644
--- a/test/benchmark/benchmarks.js
+++ b/tools/benchmark/benchmarks.js
@@ -1,6 +1,7 @@
"use strict";
const benchmarks = [
+
{
id: "json",
title: "JSON",
@@ -12,6 +13,7 @@ const benchmarks = [
{ file: "example5.json", title: "Example 5" }
]
},
+
{
id: "css",
title: "CSS",
@@ -32,7 +34,8 @@ const benchmarks = [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" }
]
- }
+ },
+
];
module.exports = benchmarks;
diff --git a/test/benchmark/index.js b/tools/benchmark/browser.js
similarity index 65%
rename from test/benchmark/index.js
rename to tools/benchmark/browser.js
index cc854fa..36056e1 100644
--- a/test/benchmark/index.js
+++ b/tools/benchmark/browser.js
@@ -16,33 +16,33 @@ $( "#run" ).click( () => {
const KB = 1024;
const MS_IN_S = 1000;
- resultsTable.append(
- "
"
- + ""
- + ( url !== null ? "" : "" )
- + title
- + ( url !== null ? "" : "" )
- + " | "
- + ""
- + ""
- + ( inputSize / KB ).toFixed( 2 )
- + ""
- + " kB"
- + " | "
- + ""
- + ""
- + parseTime.toFixed( 2 )
- + ""
- + " ms"
- + " | "
- + ""
- + ""
- + ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 )
- + ""
- + " kB/s"
- + " | "
- + "
"
- );
+ resultsTable.append( `
+
+
+ ${ url !== null ? "" : "" }
+ ${ title }
+ ${ url !== null ? "" : "" }
+ |
+
+
+ ${ ( inputSize / KB ).toFixed( 2 ) }
+
+ kB
+ |
+
+
+ ${ parseTime.toFixed( 2 ) }
+
+ ms
+ |
+
+
+ ${ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 ) }
+
+ kB/s
+ |
+
+ ` );
}
@@ -72,11 +72,12 @@ $( "#run" ).click( () => {
}
Runner.run( benchmarks, runCount, options, {
+
readFile( file ) {
return $.ajax( {
type: "GET",
- url: file,
+ url: "/" + file,
dataType: "text",
async: false
} ).responseText;
@@ -101,13 +102,13 @@ $( "#run" ).click( () => {
benchmarkStart( benchmark ) {
- resultsTable.append(
- ""
- + ""
- + benchmark.title
- + ""
- + " |
"
- );
+ resultsTable.append( `
+
+
+ ${ benchmark.title }
+ |
+
"
+ ` );
},
@@ -146,6 +147,7 @@ $( "#run" ).click( () => {
$( "#run-count, #cache, #run" ).removeAttr( "disabled" );
}
+
} );
} );
diff --git a/test/benchmark/css/960.gs/min/960.css b/tools/benchmark/css/960.gs/min/960.css
similarity index 100%
rename from test/benchmark/css/960.gs/min/960.css
rename to tools/benchmark/css/960.gs/min/960.css
diff --git a/test/benchmark/css/960.gs/min/960_24_col.css b/tools/benchmark/css/960.gs/min/960_24_col.css
similarity index 100%
rename from test/benchmark/css/960.gs/min/960_24_col.css
rename to tools/benchmark/css/960.gs/min/960_24_col.css
diff --git a/test/benchmark/css/960.gs/min/reset.css b/tools/benchmark/css/960.gs/min/reset.css
similarity index 100%
rename from test/benchmark/css/960.gs/min/reset.css
rename to tools/benchmark/css/960.gs/min/reset.css
diff --git a/test/benchmark/css/960.gs/min/text.css b/tools/benchmark/css/960.gs/min/text.css
similarity index 100%
rename from test/benchmark/css/960.gs/min/text.css
rename to tools/benchmark/css/960.gs/min/text.css
diff --git a/test/benchmark/css/960.gs/src/960.css b/tools/benchmark/css/960.gs/src/960.css
similarity index 100%
rename from test/benchmark/css/960.gs/src/960.css
rename to tools/benchmark/css/960.gs/src/960.css
diff --git a/test/benchmark/css/960.gs/src/960_24_col.css b/tools/benchmark/css/960.gs/src/960_24_col.css
similarity index 100%
rename from test/benchmark/css/960.gs/src/960_24_col.css
rename to tools/benchmark/css/960.gs/src/960_24_col.css
diff --git a/test/benchmark/css/960.gs/src/reset.css b/tools/benchmark/css/960.gs/src/reset.css
similarity index 100%
rename from test/benchmark/css/960.gs/src/reset.css
rename to tools/benchmark/css/960.gs/src/reset.css
diff --git a/test/benchmark/css/960.gs/src/text.css b/tools/benchmark/css/960.gs/src/text.css
similarity index 100%
rename from test/benchmark/css/960.gs/src/text.css
rename to tools/benchmark/css/960.gs/src/text.css
diff --git a/test/benchmark/css/blueprint/min/print.css b/tools/benchmark/css/blueprint/min/print.css
similarity index 100%
rename from test/benchmark/css/blueprint/min/print.css
rename to tools/benchmark/css/blueprint/min/print.css
diff --git a/test/benchmark/css/blueprint/min/screen.css b/tools/benchmark/css/blueprint/min/screen.css
similarity index 100%
rename from test/benchmark/css/blueprint/min/screen.css
rename to tools/benchmark/css/blueprint/min/screen.css
diff --git a/test/benchmark/css/blueprint/src/forms.css b/tools/benchmark/css/blueprint/src/forms.css
similarity index 100%
rename from test/benchmark/css/blueprint/src/forms.css
rename to tools/benchmark/css/blueprint/src/forms.css
diff --git a/test/benchmark/css/blueprint/src/grid.css b/tools/benchmark/css/blueprint/src/grid.css
similarity index 100%
rename from test/benchmark/css/blueprint/src/grid.css
rename to tools/benchmark/css/blueprint/src/grid.css
diff --git a/test/benchmark/css/blueprint/src/print.css b/tools/benchmark/css/blueprint/src/print.css
similarity index 100%
rename from test/benchmark/css/blueprint/src/print.css
rename to tools/benchmark/css/blueprint/src/print.css
diff --git a/test/benchmark/css/blueprint/src/reset.css b/tools/benchmark/css/blueprint/src/reset.css
similarity index 100%
rename from test/benchmark/css/blueprint/src/reset.css
rename to tools/benchmark/css/blueprint/src/reset.css
diff --git a/test/benchmark/css/blueprint/src/typography.css b/tools/benchmark/css/blueprint/src/typography.css
similarity index 100%
rename from test/benchmark/css/blueprint/src/typography.css
rename to tools/benchmark/css/blueprint/src/typography.css
diff --git a/test/benchmark/json/example1.json b/tools/benchmark/json/example1.json
similarity index 100%
rename from test/benchmark/json/example1.json
rename to tools/benchmark/json/example1.json
diff --git a/test/benchmark/json/example2.json b/tools/benchmark/json/example2.json
similarity index 100%
rename from test/benchmark/json/example2.json
rename to tools/benchmark/json/example2.json
diff --git a/test/benchmark/json/example3.json b/tools/benchmark/json/example3.json
similarity index 100%
rename from test/benchmark/json/example3.json
rename to tools/benchmark/json/example3.json
diff --git a/test/benchmark/json/example4.json b/tools/benchmark/json/example4.json
similarity index 100%
rename from test/benchmark/json/example4.json
rename to tools/benchmark/json/example4.json
diff --git a/test/benchmark/json/example5.json b/tools/benchmark/json/example5.json
similarity index 100%
rename from test/benchmark/json/example5.json
rename to tools/benchmark/json/example5.json
diff --git a/test/benchmark/run b/tools/benchmark/node.js
similarity index 97%
rename from test/benchmark/run
rename to tools/benchmark/node.js
index 278c8ab..0f3f78e 100644
--- a/test/benchmark/run
+++ b/tools/benchmark/node.js
@@ -207,14 +207,19 @@ if ( args.length > 0 ) {
}
Runner.run( benchmarks, runCount, options, {
+
readFile( file ) {
- return fs.readFileSync( path.join( __dirname, file ), "utf8" );
+ if ( file.startsWith( "benchmark" ) ) file = path.join( "tools", file );
+
+ return fs.readFileSync( file, "utf8" );
},
testStart() {
- // Nothing to do.
+
+ // Nothing to do.
+
},
testFinish( benchmark, test, inputSize, parseTime ) {
@@ -248,5 +253,6 @@ Runner.run( benchmarks, runCount, options, {
writeResult( "Total", inputSize, parseTime );
writeTableFooter();
- }
+ },
+
} );
diff --git a/tools/benchmark/package.json b/tools/benchmark/package.json
new file mode 100644
index 0000000..d0d29f6
--- /dev/null
+++ b/tools/benchmark/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "benchmark",
+ "version": "3.1.0",
+ "private": true,
+ "bin": "node.js"
+}
diff --git a/test/benchmark/runner.js b/tools/benchmark/runner.js
similarity index 92%
rename from test/benchmark/runner.js
rename to tools/benchmark/runner.js
index baa2dee..8134443 100644
--- a/test/benchmark/runner.js
+++ b/tools/benchmark/runner.js
@@ -3,11 +3,13 @@
const peg = require( "pegjs" );
const Runner = {
+
run( benchmarks, runCount, options, callbacks ) {
// Queue
const Q = {
+
functions: [],
add( f ) {
@@ -33,6 +35,7 @@ const Runner = {
}
}
+
};
// The benchmark itself is factored out into several functions (some of them
@@ -61,12 +64,12 @@ const Runner = {
function benchmarkInitializer( benchmark ) {
- return function () {
+ return () => {
callbacks.benchmarkStart( benchmark );
state.parser = peg.generate(
- callbacks.readFile( "../../examples/" + benchmark.id + ".pegjs" ),
+ callbacks.readFile( "examples/" + benchmark.id + ".pegjs" ),
options
);
state.benchmarkInputSize = 0;
@@ -78,11 +81,11 @@ const Runner = {
function testRunner( benchmark, test ) {
- return function () {
+ return () => {
callbacks.testStart( benchmark, test );
- const input = callbacks.readFile( benchmark.id + "/" + test.file );
+ const input = callbacks.readFile( "benchmark/" + benchmark.id + "/" + test.file );
let parseTime = 0;
for ( let i = 0; i < runCount; i++ ) {
@@ -105,7 +108,7 @@ const Runner = {
function benchmarkFinalizer( benchmark ) {
- return function () {
+ return () => {
callbacks.benchmarkFinish(
benchmark,
@@ -145,6 +148,7 @@ const Runner = {
Q.run();
}
+
};
module.exports = Runner;
diff --git a/tools/impact/index.js b/tools/impact/index.js
index 5388286..3eb2985 100644
--- a/tools/impact/index.js
+++ b/tools/impact/index.js
@@ -36,7 +36,7 @@ function binfile( ...files ) {
}
const PEGJS_BIN = binfile( "packages/pegjs/bin/peg.js", "bin/peg.js", "bin/pegjs" );
-const BENCHMARK_BIN = binfile( "test/benchmark/run", "benchmark/run" );
+const BENCHMARK_BIN = binfile( "tools/benchmark/node.js", "test/benchmark/run", "benchmark/run" );
// Utils