e6d018a88d
This is related to my last commit. I've updated all the JavaScript files to satisfy 'eslint-config-futagozaryuu', my eslint configuration. I'm sure I've probally missed something, but I've run all NPM scripts and Gulp tasks, fixed any bugs that cropped up, and updated some stuff (mainly related to generated messages), so as far as I can, tell this conversion is over (I know I've probally jixed it just by saying this ;P).
154 lines
3.8 KiB
JavaScript
154 lines
3.8 KiB
JavaScript
"use strict";
|
|
|
|
/* eslint-env browser, jquery */
|
|
|
|
const Runner = require( "./runner.js" );
|
|
const benchmarks = require( "./benchmarks.js" );
|
|
|
|
$( "#run" ).click( () => {
|
|
|
|
// Results Table Manipulation
|
|
|
|
const resultsTable = $( "#results-table" );
|
|
|
|
function appendResult( klass, title, url, inputSize, parseTime ) {
|
|
|
|
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>"
|
|
+ " <span class='unit'>kB</span>"
|
|
+ "</td>"
|
|
+ "<td class='parse-time'>"
|
|
+ "<span class='value'>"
|
|
+ parseTime.toFixed( 2 )
|
|
+ "</span>"
|
|
+ " <span class='unit'>ms</span>"
|
|
+ "</td>"
|
|
+ "<td class='parse-speed'>"
|
|
+ "<span class='value'>"
|
|
+ ( ( inputSize / KB ) / ( parseTime / MS_IN_S ) ).toFixed( 2 )
|
|
+ "</span>"
|
|
+ " <span class='unit'>kB/s</span>"
|
|
+ "</td>"
|
|
+ "</tr>"
|
|
);
|
|
|
|
}
|
|
|
|
// Main
|
|
|
|
// Each input is parsed multiple times and the results are averaged. We
|
|
// do this for two reasons:
|
|
//
|
|
// 1. To warm up the interpreter (PEG.js-generated parsers will be
|
|
// most likely used repeatedly, so it makes sense to measure
|
|
// performance after warming up).
|
|
//
|
|
// 2. To minimize random errors.
|
|
|
|
const runCount = parseInt( $( "#run-count" ).val(), 10 );
|
|
const options = {
|
|
cache: $( "#cache" ).is( ":checked" ),
|
|
optimize: $( "#optimize" ).val()
|
|
};
|
|
|
|
if ( isNaN( runCount ) || runCount <= 0 ) {
|
|
|
|
alert( "Number of runs must be a positive integer." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Runner.run( benchmarks, runCount, options, {
|
|
readFile( file ) {
|
|
|
|
return $.ajax( {
|
|
type: "GET",
|
|
url: "benchmark/" + file,
|
|
dataType: "text",
|
|
async: false
|
|
} ).responseText;
|
|
|
|
},
|
|
|
|
testStart() {
|
|
// Nothing to do.
|
|
},
|
|
|
|
testFinish( benchmark, test, inputSize, parseTime ) {
|
|
|
|
appendResult(
|
|
"individual",
|
|
test.title,
|
|
"benchmark/" + benchmark.id + "/" + test.file,
|
|
inputSize,
|
|
parseTime
|
|
);
|
|
|
|
},
|
|
|
|
benchmarkStart( benchmark ) {
|
|
|
|
resultsTable.append(
|
|
"<tr class='heading'><th colspan='4'>"
|
|
+ "<a href='../../examples/" + benchmark.id + ".pegjs'>"
|
|
+ benchmark.title
|
|
+ "</a>"
|
|
+ "</th></tr>"
|
|
);
|
|
|
|
},
|
|
|
|
benchmarkFinish( benchmark, inputSize, parseTime ) {
|
|
|
|
appendResult(
|
|
"benchmark-total",
|
|
benchmark.title + " total",
|
|
null,
|
|
inputSize,
|
|
parseTime
|
|
);
|
|
|
|
},
|
|
|
|
start() {
|
|
|
|
$( "#run-count, #cache, #run" ).attr( "disabled", "disabled" );
|
|
|
|
resultsTable.show();
|
|
$( "#results-table tr" ).slice( 1 ).remove();
|
|
|
|
},
|
|
|
|
finish( inputSize, parseTime ) {
|
|
|
|
appendResult(
|
|
"total",
|
|
"Total",
|
|
null,
|
|
inputSize,
|
|
parseTime
|
|
);
|
|
|
|
$.scrollTo( "max", { axis: "y", duration: 500 } );
|
|
$( "#run-count, #cache, #run" ).removeAttr( "disabled" );
|
|
|
|
}
|
|
} );
|
|
|
|
} );
|
|
|
|
$( document ).ready( () => $( "#run" ).focus() );
|