Browse Source

Move test/benchmark to tools/benchmark

master
Futago-za Ryuu 3 years ago
parent
commit
163ff20508
  1. 11
      gulpfile.js
  2. 2
      now.json
  3. 2
      package.json
  4. 5
      server.js
  5. 5
      tools/benchmark/benchmarks.js
  6. 72
      tools/benchmark/browser.js
  7. 0
      tools/benchmark/css/960.gs/min/960.css
  8. 0
      tools/benchmark/css/960.gs/min/960_24_col.css
  9. 0
      tools/benchmark/css/960.gs/min/reset.css
  10. 0
      tools/benchmark/css/960.gs/min/text.css
  11. 0
      tools/benchmark/css/960.gs/src/960.css
  12. 0
      tools/benchmark/css/960.gs/src/960_24_col.css
  13. 0
      tools/benchmark/css/960.gs/src/reset.css
  14. 0
      tools/benchmark/css/960.gs/src/text.css
  15. 0
      tools/benchmark/css/blueprint/min/print.css
  16. 0
      tools/benchmark/css/blueprint/min/screen.css
  17. 0
      tools/benchmark/css/blueprint/src/forms.css
  18. 0
      tools/benchmark/css/blueprint/src/grid.css
  19. 0
      tools/benchmark/css/blueprint/src/print.css
  20. 0
      tools/benchmark/css/blueprint/src/reset.css
  21. 0
      tools/benchmark/css/blueprint/src/typography.css
  22. 0
      tools/benchmark/json/example1.json
  23. 0
      tools/benchmark/json/example2.json
  24. 0
      tools/benchmark/json/example3.json
  25. 0
      tools/benchmark/json/example4.json
  26. 0
      tools/benchmark/json/example5.json
  27. 12
      tools/benchmark/node.js
  28. 6
      tools/benchmark/package.json
  29. 14
      tools/benchmark/runner.js
  30. 2
      tools/impact/index.js

11
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", () =>

2
now.json

@ -13,8 +13,10 @@
"examples",
"packages",
"test",
"tools/benchmark",
"website",
".babelrc.js",
"package.json",
"server.js",
"yarn.lock"
]

2
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",

5
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/**"
],
},

5
test/benchmark/benchmarks.js → 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;

72
test/benchmark/index.js → tools/benchmark/browser.js

@ -16,33 +16,33 @@ $( "#run" ).click( () => {
const KB = 1024;
const MS_IN_S = 1000;
resultsTable.append(
"<tr class='" + klass + "'>"
+ "<td class='title'>"
+ ( url !== null ? "<a href='" + url + "'>" : "" )
+ title
+ ( url !== null ? "</a>" : "" )
+ "</td>"
+ "<td class='input-size'>"
+ "<span class='value'>"
+ ( inputSize / KB ).toFixed( 2 )
+ "</span>"
+ "&nbsp;<span class='unit'>kB</span>"
+ "</td>"
+ "<td class='parse-time'>"
+ "<span class='value'>"
+ parseTime.toFixed( 2 )
+ "</span>"
+ "&nbsp;<span class='unit'>ms</span>"
+ "</td>"
+ "<td class='parse-speed'>"
+ "<span class='value'>"
+ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 )
+ "</span>"
+ "&nbsp;<span class='unit'>kB/s</span>"
+ "</td>"
+ "</tr>"
);
resultsTable.append( `
<tr class='${ klass }'>
<td class='title'>
${ url !== null ? "<a href='" + url + "'>" : "" }
${ title }
${ url !== null ? "</a>" : "" }
</td>
<td class='input-size'>
<span class='value'>
${ ( inputSize / KB ).toFixed( 2 ) }
</span>
&nbsp;<span class='unit'>kB</span>
</td>
<td class='parse-time'>
<span class='value'>
${ parseTime.toFixed( 2 ) }
</span>
&nbsp;<span class='unit'>ms</span>
</td>
<td class='parse-speed'>
<span class='value'>
${ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 ) }
</span>
&nbsp;<span class='unit'>kB/s</span>
</td>
</tr>
` );
}
@ -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(
"<tr class='heading'><th colspan='4'>"
+ "<a href='../../examples/" + benchmark.id + ".pegjs'>"
+ benchmark.title
+ "</a>"
+ "</th></tr>"
);
resultsTable.append( `
<tr class='heading'>
<th colspan='4'>
<a href='examples/${ benchmark.id }.pegjs'> ${ benchmark.title } </a>
</th>
</tr>"
` );
},
@ -146,6 +147,7 @@ $( "#run" ).click( () => {
$( "#run-count, #cache, #run" ).removeAttr( "disabled" );
}
} );
} );

0
test/benchmark/css/960.gs/min/960.css → tools/benchmark/css/960.gs/min/960.css

0
test/benchmark/css/960.gs/min/960_24_col.css → tools/benchmark/css/960.gs/min/960_24_col.css

0
test/benchmark/css/960.gs/min/reset.css → tools/benchmark/css/960.gs/min/reset.css

0
test/benchmark/css/960.gs/min/text.css → tools/benchmark/css/960.gs/min/text.css

0
test/benchmark/css/960.gs/src/960.css → tools/benchmark/css/960.gs/src/960.css

0
test/benchmark/css/960.gs/src/960_24_col.css → tools/benchmark/css/960.gs/src/960_24_col.css

0
test/benchmark/css/960.gs/src/reset.css → tools/benchmark/css/960.gs/src/reset.css

0
test/benchmark/css/960.gs/src/text.css → tools/benchmark/css/960.gs/src/text.css

0
test/benchmark/css/blueprint/min/print.css → tools/benchmark/css/blueprint/min/print.css

0
test/benchmark/css/blueprint/min/screen.css → tools/benchmark/css/blueprint/min/screen.css

0
test/benchmark/css/blueprint/src/forms.css → tools/benchmark/css/blueprint/src/forms.css

0
test/benchmark/css/blueprint/src/grid.css → tools/benchmark/css/blueprint/src/grid.css

0
test/benchmark/css/blueprint/src/print.css → tools/benchmark/css/blueprint/src/print.css

0
test/benchmark/css/blueprint/src/reset.css → tools/benchmark/css/blueprint/src/reset.css

0
test/benchmark/css/blueprint/src/typography.css → tools/benchmark/css/blueprint/src/typography.css

0
test/benchmark/json/example1.json → tools/benchmark/json/example1.json

0
test/benchmark/json/example2.json → tools/benchmark/json/example2.json

0
test/benchmark/json/example3.json → tools/benchmark/json/example3.json

0
test/benchmark/json/example4.json → tools/benchmark/json/example4.json

0
test/benchmark/json/example5.json → tools/benchmark/json/example5.json

12
test/benchmark/run → 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();
}
},
} );

6
tools/benchmark/package.json

@ -0,0 +1,6 @@
{
"name": "benchmark",
"version": "3.1.0",
"private": true,
"bin": "node.js"
}

14
test/benchmark/runner.js → 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;

2
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

Loading…
Cancel
Save