Skip to content

Commit

Permalink
Cleaned up benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-steele-idem committed Jan 24, 2017
1 parent ab89ea1 commit 1f5986c
Show file tree
Hide file tree
Showing 91 changed files with 4,785 additions and 2,065 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
@@ -1,4 +1,5 @@
*.marko.js
/node_modules
/static
/.cache
/build
/.cache
.*
2 changes: 1 addition & 1 deletion .jshintrc
Expand Up @@ -3,7 +3,7 @@
"Promise"
],
"node" : true,
"es5" : false,
"esnext" : true,
"browser" : true,
"boss" : false,
"curly": false,
Expand Down
9 changes: 9 additions & 0 deletions benchmark-client/browser.json
@@ -0,0 +1,9 @@
{
"dependencies": [
"lodash/lodash.js",
"benchmark/benchmark.js",
"require: ./components/app",
"require-run: ./client",
"require-run: ../benchmarks/*/client.js"
]
}
19 changes: 19 additions & 0 deletions benchmark-client/client.js
@@ -0,0 +1,19 @@
var helpers = require('./helpers');

function addBench(libName, factoryFunc) {
var benchmark = exports.benchmark;
var bench = benchmark.createBench(libName, factoryFunc);
benchmark.benches[libName] = bench;
}

function registerBenchmark(factoryFunc) {
var benchmark = factoryFunc(helpers);
benchmark.benches = {};
exports.benchmark = benchmark;
}

if (typeof window !== 'undefined') {
window.addBench = addBench;
window.registerBenchmark = registerBenchmark;
window.onMount = function() {};
}
@@ -1,20 +1,21 @@
require('./style.css');
var benchmark = require('~/src/shared/util/benchmark');

var benchmarks = {
'search-results': require('./benchmark-search-results')
};
var runBenchmark = require('../../runBenchmark');
var client = require('../../client');

module.exports = {
init: function() {
this.running = false;
onInput: function(input) {
this.state = {
running: false,
benchmarkName: input.benchmark.name
};
},

handleBenchmarkButtonClick: function(benchmarkName, event, el) {
if (this.running) {
handleBenchmarkButtonClick: function(event, el) {
if (this.state.running) {
return;
}

var benchmarkName = this.state.benchmarkName;

var oldButtonLabel = el.innerHTML;
el.innerHTML = oldButtonLabel + ' - running...';

Expand All @@ -23,7 +24,7 @@ module.exports = {

var self = this;

benchmark(benchmarkName, benchmarks[benchmarkName])
runBenchmark(benchmarkName, client.benchmark)
.on('start', function(event) {
resultsEl.innerHTML += 'Running "' + benchmarkName + '"...\n';
})
Expand Down
11 changes: 11 additions & 0 deletions benchmark-client/components/app/index.marko
@@ -0,0 +1,11 @@
<div>
<button type="button" onClick("handleBenchmarkButtonClick")>
Run benchmark: ${state.benchmarkName}
</button>

<pre ref="results" style="width: 100%; border: 1px solid black;" no-update/>

<div#mount>

</div>
</div>
13 changes: 13 additions & 0 deletions benchmark-client/components/mount-container/index.marko
@@ -0,0 +1,13 @@
<script>
module.exports = {
};
</script>

<div.mount-container ref="foo">
<h1>${data.libName}</h1>
<div>
<div ref="output">
</div>
</div>
</div>
@@ -1,5 +1,6 @@
.benchmark-container {
.mount-container {
height: 600px;
width: 300px;
overflow: scroll;
display: inline-block;
}
24 changes: 24 additions & 0 deletions benchmark-client/createRoute.js
@@ -0,0 +1,24 @@
var template = require('./page.marko');

var isProduction = process.env.NODE_ENV === 'production';

function createRoute(benchmark, routeOptions) {
var bundles = [];
benchmark.benches.forEach((bench) => {
// if (bench.name !== 'marko') {
// return;
// }
bundles.push(`/build/${benchmark.name}/bundles${isProduction ? '.min' : ''}/${bench.name}.js`);
});

return function(req, res) {
res.marko(template, {
$global: {
benchmark
},
bundles
});
};
}

module.exports = createRoute;
40 changes: 40 additions & 0 deletions benchmark-client/helpers.js
@@ -0,0 +1,40 @@
var mountContainer = require('./components/mount-container');

var mountEls = {};

function createMountEl(libName) {
var key = libName;
var mountWidget = mountContainer.renderSync({
libName: libName
})
.appendTo(document.getElementById('mount'))
.getWidget();

mountEls[key] = mountWidget.el;

return mountWidget.getEl('output');
}

function showSingleMountEl(libName) {
var key = libName;

for (var curKey in mountEls) {
var mountEl = mountEls[curKey];
if (curKey === key) {
mountEl.style.display = 'inline-block';
} else {
mountEl.style.display = 'none';
}
}
}

function showMountEl(libName) {
var key = libName;

var mountEl = mountEls[key];
mountEl.style.display = 'inline-block';
}

exports.createMountEl = createMountEl;
exports.showSingleMountEl = showSingleMountEl;
exports.showMountEl = showMountEl;
@@ -1,20 +1,28 @@
import fs from 'fs';
import path from 'path';

<lasso-page package-path="./browser.json"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Benchmarks</title>
<title>${out.global.benchmark.name} | Marko Benchmark</title>
<lasso-head/>
</head>
<body>
<h1>Benchmarks</h1>
<h1>${out.global.benchmark.name} | Marko Benchmark</h1>

<app/>
<app benchmark=out.global.benchmark/>

<!--
Inject the body <script> tags to include the required client-side code:
-->
<lasso-body/>
<init-widgets/>

<for(bundle in data.bundles)>
<script src=bundle></script>
</for>

<!--
If launched using the browser-refresh app launcher then a <script>
Expand Down
Expand Up @@ -16,7 +16,7 @@ function delay(durationMillis) {
});
}

module.exports = function(name, options) {
module.exports = function runBenchmark(name, options) {

var Suite = window.Benchmark.Suite;
var suite = new Suite(name);
Expand Down Expand Up @@ -77,6 +77,7 @@ module.exports = function(name, options) {
}

bench = Object.assign({name: name}, bench);
bench.events = benchEvents;

suite.add(name, {
// a flag to indicate the benchmark is deferred
Expand Down Expand Up @@ -137,6 +138,10 @@ module.exports = function(name, options) {
function warmup() {
suiteEvents.emit('warmup');

benches.forEach(function(bench) {
bench.events.emit('warmup');
});

var index = 0;
var totalCount = 100;

Expand Down

0 comments on commit 1f5986c

Please sign in to comment.