Move test/benchmark to tools/benchmark

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

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

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

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

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

@ -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;

@ -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" );
}
} );
} );

@ -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();
}
},
} );

@ -0,0 +1,6 @@
{
"name": "benchmark",
"version": "3.1.0",
"private": true,
"bin": "node.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;

@ -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