Move test/benchmark to tools/benchmark

master
Futago-za Ryuu 6 years ago
parent 9c039ce79b
commit 163ff20508

@ -11,10 +11,8 @@ task( "lint", () => [
src( [ src( [
"**/.*rc.js", "**/.*rc.js",
"packages/**/*.js", "packages/**/*.js",
"test/benchmark/**/*.js",
"test/benchmark/run",
"test/impact",
"test/spec/**/*.js", "test/spec/**/*.js",
"tools/**/*.js",
"src/*.js", "src/*.js",
"rollup.config.js", "rollup.config.js",
"gulpfile.js", "gulpfile.js",
@ -33,13 +31,6 @@ task( "test", () =>
); );
// Run benchmarks.
task( "benchmark", () =>
run( "node test/benchmark/run" )
);
// Generate the grammar parser. // Generate the grammar parser.
task( "build:parser", () => task( "build:parser", () =>

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

@ -8,7 +8,7 @@
"scripts": { "scripts": {
"lint": "gulp lint", "lint": "gulp lint",
"spec": "gulp test", "spec": "gulp test",
"benchmark": "gulp benchmark", "benchmark": "benchmark",
"build:parser": "gulp build:parser", "build:parser": "gulp build:parser",
"build:dist": "rollup -c", "build:dist": "rollup -c",
"clean": "gulp clean", "clean": "gulp clean",

@ -32,7 +32,7 @@ app.set( "view engine", "ejs" );
app.use( logger( "dev" ) ); app.use( logger( "dev" ) );
app.use( express.static( path( "website" ) ) ); 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( "/examples", express.static( path( "examples" ) ) );
app.use( layout() ); app.use( layout() );
@ -133,7 +133,7 @@ babelOptions.exclude = "node_modules/**";
babelOptions.runtimeHelpers = true; babelOptions.runtimeHelpers = true;
[ [
{ name: "benchmark", input: "test/benchmark/**/*.js" }, { name: "benchmark", input: "tools/benchmark/browser.js" },
{ name: "spec", input: "test/spec/**/*.js" }, { name: "spec", input: "test/spec/**/*.js" },
{ name: "peg", input: "packages/pegjs/lib/peg.js", format: "umd" }, { name: "peg", input: "packages/pegjs/lib/peg.js", format: "umd" },
@ -219,6 +219,7 @@ babelOptions.runtimeHelpers = true;
include: [ include: [
"packages/**", "packages/**",
"test/**", "test/**",
"tools/benchmark/**"
], ],
}, },

@ -1,6 +1,7 @@
"use strict"; "use strict";
const benchmarks = [ const benchmarks = [
{ {
id: "json", id: "json",
title: "JSON", title: "JSON",
@ -12,6 +13,7 @@ const benchmarks = [
{ file: "example5.json", title: "Example 5" } { file: "example5.json", title: "Example 5" }
] ]
}, },
{ {
id: "css", id: "css",
title: "CSS", title: "CSS",
@ -32,7 +34,8 @@ const benchmarks = [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" }, { file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" } { file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" }
] ]
} },
]; ];
module.exports = benchmarks; module.exports = benchmarks;

@ -16,33 +16,33 @@ $( "#run" ).click( () => {
const KB = 1024; const KB = 1024;
const MS_IN_S = 1000; const MS_IN_S = 1000;
resultsTable.append( resultsTable.append( `
"<tr class='" + klass + "'>" <tr class='${ klass }'>
+ "<td class='title'>" <td class='title'>
+ ( url !== null ? "<a href='" + url + "'>" : "" ) ${ url !== null ? "<a href='" + url + "'>" : "" }
+ title ${ title }
+ ( url !== null ? "</a>" : "" ) ${ url !== null ? "</a>" : "" }
+ "</td>" </td>
+ "<td class='input-size'>" <td class='input-size'>
+ "<span class='value'>" <span class='value'>
+ ( inputSize / KB ).toFixed( 2 ) ${ ( inputSize / KB ).toFixed( 2 ) }
+ "</span>" </span>
+ "&nbsp;<span class='unit'>kB</span>" &nbsp;<span class='unit'>kB</span>
+ "</td>" </td>
+ "<td class='parse-time'>" <td class='parse-time'>
+ "<span class='value'>" <span class='value'>
+ parseTime.toFixed( 2 ) ${ parseTime.toFixed( 2 ) }
+ "</span>" </span>
+ "&nbsp;<span class='unit'>ms</span>" &nbsp;<span class='unit'>ms</span>
+ "</td>" </td>
+ "<td class='parse-speed'>" <td class='parse-speed'>
+ "<span class='value'>" <span class='value'>
+ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 ) ${ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 ) }
+ "</span>" </span>
+ "&nbsp;<span class='unit'>kB/s</span>" &nbsp;<span class='unit'>kB/s</span>
+ "</td>" </td>
+ "</tr>" </tr>
); ` );
} }
@ -72,11 +72,12 @@ $( "#run" ).click( () => {
} }
Runner.run( benchmarks, runCount, options, { Runner.run( benchmarks, runCount, options, {
readFile( file ) { readFile( file ) {
return $.ajax( { return $.ajax( {
type: "GET", type: "GET",
url: file, url: "/" + file,
dataType: "text", dataType: "text",
async: false async: false
} ).responseText; } ).responseText;
@ -101,13 +102,13 @@ $( "#run" ).click( () => {
benchmarkStart( benchmark ) { benchmarkStart( benchmark ) {
resultsTable.append( resultsTable.append( `
"<tr class='heading'><th colspan='4'>" <tr class='heading'>
+ "<a href='../../examples/" + benchmark.id + ".pegjs'>" <th colspan='4'>
+ benchmark.title <a href='examples/${ benchmark.id }.pegjs'> ${ benchmark.title } </a>
+ "</a>" </th>
+ "</th></tr>" </tr>"
); ` );
}, },
@ -146,6 +147,7 @@ $( "#run" ).click( () => {
$( "#run-count, #cache, #run" ).removeAttr( "disabled" ); $( "#run-count, #cache, #run" ).removeAttr( "disabled" );
} }
} ); } );
} ); } );

@ -207,14 +207,19 @@ if ( args.length > 0 ) {
} }
Runner.run( benchmarks, runCount, options, { Runner.run( benchmarks, runCount, options, {
readFile( file ) { 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() { testStart() {
// Nothing to do.
// Nothing to do.
}, },
testFinish( benchmark, test, inputSize, parseTime ) { testFinish( benchmark, test, inputSize, parseTime ) {
@ -248,5 +253,6 @@ Runner.run( benchmarks, runCount, options, {
writeResult( "Total", inputSize, parseTime ); writeResult( "Total", inputSize, parseTime );
writeTableFooter(); writeTableFooter();
} },
} ); } );

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

@ -3,11 +3,13 @@
const peg = require( "pegjs" ); const peg = require( "pegjs" );
const Runner = { const Runner = {
run( benchmarks, runCount, options, callbacks ) { run( benchmarks, runCount, options, callbacks ) {
// Queue // Queue
const Q = { const Q = {
functions: [], functions: [],
add( f ) { add( f ) {
@ -33,6 +35,7 @@ const Runner = {
} }
} }
}; };
// The benchmark itself is factored out into several functions (some of them // The benchmark itself is factored out into several functions (some of them
@ -61,12 +64,12 @@ const Runner = {
function benchmarkInitializer( benchmark ) { function benchmarkInitializer( benchmark ) {
return function () { return () => {
callbacks.benchmarkStart( benchmark ); callbacks.benchmarkStart( benchmark );
state.parser = peg.generate( state.parser = peg.generate(
callbacks.readFile( "../../examples/" + benchmark.id + ".pegjs" ), callbacks.readFile( "examples/" + benchmark.id + ".pegjs" ),
options options
); );
state.benchmarkInputSize = 0; state.benchmarkInputSize = 0;
@ -78,11 +81,11 @@ const Runner = {
function testRunner( benchmark, test ) { function testRunner( benchmark, test ) {
return function () { return () => {
callbacks.testStart( benchmark, test ); callbacks.testStart( benchmark, test );
const input = callbacks.readFile( benchmark.id + "/" + test.file ); const input = callbacks.readFile( "benchmark/" + benchmark.id + "/" + test.file );
let parseTime = 0; let parseTime = 0;
for ( let i = 0; i < runCount; i++ ) { for ( let i = 0; i < runCount; i++ ) {
@ -105,7 +108,7 @@ const Runner = {
function benchmarkFinalizer( benchmark ) { function benchmarkFinalizer( benchmark ) {
return function () { return () => {
callbacks.benchmarkFinish( callbacks.benchmarkFinish(
benchmark, benchmark,
@ -145,6 +148,7 @@ const Runner = {
Q.run(); Q.run();
} }
}; };
module.exports = Runner; module.exports = Runner;

@ -36,7 +36,7 @@ function binfile( ...files ) {
} }
const PEGJS_BIN = binfile( "packages/pegjs/bin/peg.js", "bin/peg.js", "bin/pegjs" ); 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 // Utils

Loading…
Cancel
Save