Skip to content

Commit

Permalink
update perf suite to include first/min/max times, setup for steps, an…
Browse files Browse the repository at this point in the history
…d updated minor versions
  • Loading branch information
evs-chris committed Jul 17, 2017
1 parent 59421fe commit 03bbed4
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 61 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"eslint": "^3.14.0",
"fs-plus": "^3.0.0",
"gobble": "^0.12.0",
"gobble-buble": "^0.14.0",
"gobble-cli": "^0.8.0",
"gobble-uglifyjs": "^0.2.1",
"istanbul": "^0.4.5",
Expand All @@ -36,6 +37,7 @@
"dev:browser": "gobble --env=dev:browser serve",
"dev:node": "",
"dev:bin": "",
"dev:perf": "cd perf; gobble",
"lint:src": "eslint src",
"lint:tests:browser": "eslint tests/browser",
"lint:tests:node": "eslint tests/node",
Expand Down
2 changes: 1 addition & 1 deletion perf/gobblefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = gobble([
gobble( 'control' ).moveTo( 'builds/control' ),

// most recent build
gobble( '../build' ).moveTo( 'builds/edge' ),
gobble( '../.build' ).moveTo( 'builds/edge' ),

gobble( 'tests' ).transform( 'buble' ).transform( function ( inputdir, outputdir, options ) {
var pageTemplate, indexTemplate;
Expand Down
46 changes: 37 additions & 9 deletions perf/src/app/runSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function runTest ( context, test, version, ractiveUrl, callback ) {

// setup test
context.setupComplete = function ( err, setupResult ) {
var start, runStart, duration, totalDuration, count = 0, label = version + ': ' + test.name, steps = [], died = false;
var start, runStart, duration, totalDuration, count = 0, label = version + ': ' + test.name, steps = [], died = false, min, max, durs = [];

if ( err ) {
return callback( err );
Expand All @@ -88,7 +88,7 @@ function runTest ( context, test, version, ractiveUrl, callback ) {
if ( shouldProfile || test.profile ) console.profile( label );

start = now();
duration = totalDuration = 0;
duration = totalDuration = min = max = 0;

context.setupResult = setupResult;

Expand Down Expand Up @@ -123,8 +123,12 @@ function runTest ( context, test, version, ractiveUrl, callback ) {
return callback( e );
}

duration += now() - runStart;
totalDuration = now() - start;
var dur = now() - runStart;
duration += dur;
durs.push( dur );
if ( !min || dur < min ) min = dur;
if ( dur > max ) max = dur;
totalDuration += dur;
}

if ( shouldProfile || test.profile ) console.profileEnd( label );
Expand All @@ -139,7 +143,10 @@ function runTest ( context, test, version, ractiveUrl, callback ) {
count: count,
steps,
duration: duration,
average: duration / count
average: duration / count,
min: min,
max: max,
durations: durs
});
};

Expand All @@ -155,12 +162,24 @@ function runTest ( context, test, version, ractiveUrl, callback ) {
}

function runStep ( context, test, callback ) {
let start = now(), count = 0, runStart;
let duration = 0, totalDuration = 0;
let start = now(), count = 0, runStart, setupStart;
let duration = 0, totalDuration = 0, min = 0, max = 0;
let durs = [], setups = [], setup;

console.group( test.name );

if ( typeof test.setup === 'function' ) {
setupStart = now();
context.eval( '(' + test.setup.toString() + ')()' );
setup = now() - setupStart;
}

while ( duration < ( test.max || durationMax ) && totalDuration < ( test.totalMax || totalDurationMax ) ) {
if ( typeof test.beforeEach === 'function' ) {
setupStart = now();
context.eval( '(' + test.beforeEach.toString() + ')()' );
setups.push( now() - setupStart );
}
runStart = now();
count++;

Expand All @@ -170,7 +189,11 @@ function runStep ( context, test, callback ) {
return callback( e, { name: test.name } );
}

duration += now() - runStart;
var dur = now() - runStart;
duration += dur;
durs.push( dur );
if ( !min || dur < min ) min = dur;
if ( dur > max ) max = dur;
totalDuration = now() - start;

if ( test.maxCount && count >= test.maxCount ) break;
Expand All @@ -180,7 +203,12 @@ function runStep ( context, test, callback ) {
name: test.name,
duration,
count,
average: duration / count
average: duration / count,
min,
max,
durations: durs,
setups,
setup
});

console.groupEnd( test.name );
Expand Down
22 changes: 16 additions & 6 deletions perf/src/templates/testpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,26 @@ <h1>Ractive.js performance tests</h1>
{{/if}}
{{#if results}}
<table>
<thead><tr><th>test name</th><th>iterations</th><th>avg. duration</th></tr></thead>
<thead><tr><th>test name</th><th>iterations</th><th>first</th><th>avg</th><th>min</th><th>max</th></tr></thead>

<tbody>
{{#each tests}}
<tr>
<td on-click='runInNewWindow(test,version,ractiveUrl)'>{{name}}</td><td>{{count}}</td><td>{{formatTime(average)}}</td>
<tr title="{{.durations.map(formatTime).join(', ')}}">
<td on-click='runInNewWindow(test,version,ractiveUrl)'>{{name}}</td>
<td>{{count}}</td>
<td>{{typeof .durations[0] === 'number' ? formatTime(.durations[0]) : 'n/a'}}</td>
<td>{{formatTime(average)}}</td>
<td>{{formatTime(min)}}</td>
<td>{{formatTime(max)}}</td>
</tr>
{{#each .steps}}
<tr>
<td {{#if .error}}class='error'{{/if}}>&gt;&gt;&gt; {{.name}}{{#if .error}}<br />{{.error.message}}{{/if}}</td><td>{{.count}}</td><td>{{formatTime(.average)}}</td>
<tr title="{{.durations.map(formatTime).join(', ')}}">
<td {{#if .error}}class='error'{{/if}} title="{{typeof .setup === 'number' ? formatTime(.setup) : 'no setup'}}">&gt;&gt;&gt; {{.name}}{{#if .error}}<br />{{.error.message}}{{/if}}</td>
<td>{{.count}}</td>
<td>{{typeof .durations[0] === 'number' ? formatTime(.durations[0]) : 'n/a'}}</td>
<td title="{{.setups.map(formatTime).join(', ')}}">{{formatTime(.average)}}</td>
<td>{{formatTime(min)}}</td>
<td>{{formatTime(max)}}</td>
</tr>
{{/each}}
{{/each}}
Expand All @@ -170,7 +180,7 @@ <h1>Ractive.js performance tests</h1>
template: '#template',
data: {
running: false,
versions: [ '0.4.0', '0.5.0', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.6.0', '0.6.1', '0.7.2', '0.7.3', '0.8.10', 'edge', 'control', 'dev' ],
versions: [ '0.4.0', '0.5.0', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.6.0', '0.6.1', '0.7.2', '0.7.3', '0.8.14', '0.9.2', 'edge', 'control', 'dev' ],
selectedVersion: 'dev',
results: [],
formatTime: function ( ms ) {
Expand Down
89 changes: 44 additions & 45 deletions perf/tests/jsweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ var tests = [
{
name: 'js web framework benchmark approximation',
test: [
{
name: 'parse',
maxCount: 10,
test() {
window.tpl = Ractive.parse(
`<table>
<tr><th>name</th><th>index</th><th>remove</th></tr>
{{#if show}}
{{#rows:i}}
<tr class="{{#if ~/selected === .id}}selected{{/if}}">
<td>{{.id}}</td>
<td>{{.name}}</td>
<td>{{i}} - {{@index}}</td>
<td><button on-click="remove:{{i}}">remove</button></td>
</tr>
{{/rows}}
{{/if}}
</table>`
);
}
},
{
name: 'init',
max: 1,
maxCount: 1,
test() {
var r = window.ractive = new Ractive({
el: 'body',
template:
`<table>
<tr><th>name</th><th>index</th><th>remove</th></tr>
{{#if show}}
{{#rows:i}}
<tr class="{{#if ~/selected === .id}}selected{{/if}}">
<td>{{.id}}</td>
<td>{{.name}}</td>
<td>{{i}} - {{@index}}</td>
<td><button on-click="remove:{{i}}">remove</button></td>
</tr>
{{/rows}}
{{/if}}
</table>`,
template: window.tpl,
data: { rows: [], show: true }
});
var id = 0;
Expand Down Expand Up @@ -51,8 +59,10 @@ var tests = [
name: 'create 1000 rows',
max: 1500,
totalMax: 5000,
test() {
beforeEach() {
ractive.set( 'rows', [] );
},
test() {
ractive.set( 'rows', gen() );
}
},
Expand All @@ -76,15 +86,11 @@ var tests = [
},

{
name: 'reset to 1000 rows',
test() {
name: 'remove random row',
setup() {
/* global ractive, gen */
ractive.set( 'rows', gen() );
}
},

{
name: 'remove random row',
},
test() {
/* global ractive, random */
ractive.splice( 'rows', random( ractive.get( 'rows' ).length - 1 ), 1 );
Expand All @@ -93,15 +99,11 @@ var tests = [
},

{
name: 'reset to 1000 rows',
test() {
name: 'remove first row',
beforeEach() {
/* global ractive, gen */
ractive.set( 'rows', gen() );
}
},

{
name: 'remove first row',
},
test() {
/* global ractive */
ractive.shift( 'rows' );
Expand All @@ -110,15 +112,11 @@ var tests = [
},

{
name: 'reset to 1000 rows',
test() {
name: 'remove last row',
beforeEach() {
/* global ractive, gen */
ractive.set( 'rows', gen() );
}
},

{
name: 'remove last row',
},
test() {
/* global ractive */
ractive.pop( 'rows' );
Expand All @@ -127,15 +125,11 @@ var tests = [
},

{
name: 'reset to 1000 rows',
test() {
name: 'hide rows',
setup() {
/* global ractive, gen */
ractive.set( 'rows', gen() );
}
},

{
name: 'hide rows',
},
test() {
/* global ractive */
ractive.set( 'show', false );
Expand Down Expand Up @@ -195,10 +189,15 @@ var tests = [

{
name: 'generate 10,000 rows',
beforeEach() {
ractive.set( 'rows', [] );
},
test() {
/* global ractive, gen */
ractive.set( 'rows', gen( 10000 ) );
}
},
totalMax: 10000,
max: 5000
},

{
Expand Down

0 comments on commit 03bbed4

Please sign in to comment.