Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Perf tests dev, continued
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Rudenko committed Jul 18, 2012
1 parent 1120389 commit eceb559
Show file tree
Hide file tree
Showing 33 changed files with 1,228 additions and 59 deletions.
16 changes: 8 additions & 8 deletions test/integration/analyzeDeltas.js
Expand Up @@ -24,20 +24,20 @@
'infinity': 1.96 'infinity': 1.96
}; };


window.analyzeDeltas = function(timingPoints) { module.exports = function(timingPoints) {
var deltas = []; var deltas = [];
timingPoints.forEach(function(run) { timingPoints.forEach(function(run) {
run.forEach(function(entry, i) { run.forEach(function(entry, i) {
var lastEntry = i ? run[i-1] : entry; var lastEntry = run[(run.length + i-1) % run.length];
var delta = entry[0] - lastEntry[0]; var delta = Math.abs(entry[0] - lastEntry[0]);


deltas[i] = deltas[i] || []; deltas[i] = deltas[i] || [];
deltas[i].name = entry[1]; deltas[i].name = i ? entry[1] : 'Total';
deltas[i].push(delta / 1e3); deltas[i].push(delta / 1e3);
}) })
}); });


deltas.forEach(function(delta) { return deltas.map(function(delta) {
delta.mean = getMean(delta); delta.mean = getMean(delta);
// sample variance (estimate of the population variance) // sample variance (estimate of the population variance)
delta.variance = delta.reduce( delta.variance = delta.reduce(
Expand All @@ -57,8 +57,8 @@
// relative margin of error // relative margin of error
delta.rme = (delta.moe / delta.mean) * 100 || 0; delta.rme = (delta.moe / delta.mean) * 100 || 0;


log(' ' + delta.name + ', avg ' + (delta.mean * 1e3).toFixed(2) + 'ms \xb1' return ' ' + delta.name + ', avg ' + (delta.mean * 1e3).toFixed(2) + 'ms +/-'
+ delta.rme.toFixed(2) + '%'); + delta.rme.toFixed(2) + '%';
}); }).join('\n');
}; };
})(); })();
49 changes: 34 additions & 15 deletions test/integration/mobifyjs.coffee
Expand Up @@ -17,8 +17,10 @@ Injector = require '../../src/injector.coffee'
{Project} = require '../../src/project.coffee' {Project} = require '../../src/project.coffee'
Preview = require '../../src/preview.coffee' Preview = require '../../src/preview.coffee'
Scaffold = require '../../src/scaffold.coffee' Scaffold = require '../../src/scaffold.coffee'
analyzeDeltas = require './analyzeDeltas.js'


PORT = { STATIC: 1341, TAG: 1342, PREVIEW: 8080 } PORT = { STATIC: 1341, TAG: 1342, PREVIEW: 8080 }
PERF_ITERATIONS = 50
requestLog = []; requestLog = [];
logRequests = () -> logRequests = () ->
result = requestLog.join('\n') result = requestLog.join('\n')
Expand All @@ -39,15 +41,35 @@ program


start = (mode) -> start = (mode) ->
integrationDir = "#{__dirname}/../integration" integrationDir = "#{__dirname}/../integration"
tests = fs.readdirSync(integrationDir + '/' + mode).filter((x) -> x.match(/^\d+\.[^.]+$/)) tests = fs.readdirSync(integrationDir + '/' + mode)
.filter((x) -> x.match(/^\d+\.[^.]+$/))


# Static Server # Static Server
@static = new Connect() @static = new Connect()
.use(Connect.query()) .use(Connect.query())
.use(Connect.cookieParser())
.use(Connect.session({ secret: "keyboard cat" }))
.use('/', (req, res, next) -> .use('/', (req, res, next) ->
return next() if req.query.tests or req.url != '/' if !req.query.tests and req.url == '/'
res.writeHead(302, {Location: req.url + '?mode=' + mode + '&tests=' + tests.join('+')}) res.writeHead(302, {Location: req.url + "?mode=#{mode}&tests=" + tests.join('+')})
res.end() res.end()
return

if +req.query.iter >= PERF_ITERATIONS
if (req.query.tests and req.query.tests.length)
remainingTests = req.query.tests;
res.writeHead(302, {Location: "/?mode=#{mode}&tests=#{remainingTests}"})
else
res.writeHead(302, {Location: "/done"})
res.end()
return


if (req.query.perf)
url = req.url.split('?')[0].split('/').pop().replace(/\.html$/, '')
console.log('RECORDING', url)
req.session[url] = (req.session[url] || '') + req.query.perf + '\n'
next()
) )
.use(Connect.static integrationDir) .use(Connect.static integrationDir)
.use(Connect.middleware.logger((request, result) -> .use(Connect.middleware.logger((request, result) ->
Expand All @@ -65,17 +87,14 @@ start = (mode) ->
) )
) )
.use('/end', (req, res) -> .use('/end', (req, res) ->
res.end logRequests() res.end(logRequests())
) )
.use('/submit', (req, res) -> .use('/done', (req, res) ->
body = '' for key in tests
req.on('data', (data) -> results = JSON.parse('[' + req.session[key].split('\n').join(',') + '0]')
body += data; results.pop()
) res.write(key + '\n' + analyzeDeltas(results) + '\n')
req.on('end', () -> res.end()
console.log(body)
res.end
)
) )
.use('/start', (req, res) -> .use('/start', (req, res) ->
logRequests() logRequests()
Expand All @@ -86,7 +105,7 @@ start = (mode) ->


project = Project.load "test/integration/#{mode}#{target}/project.json" project = Project.load "test/integration/#{mode}#{target}/project.json"
project.build_directory = "test/integration/#{mode}#{target}/bld" project.build_directory = "test/integration/#{mode}#{target}/bld"
project.build({ test: true, }, (err) -> project.build({ test: true, production:false }, (err) ->
if err if err
error = "Failed to build #{target}. Error: #{err}" error = "Failed to build #{target}. Error: #{err}"
console.log(error) console.log(error)
Expand Down

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions test/integration/performance/02.basicResource/src/mobify.konf
Expand Up @@ -3,8 +3,21 @@
{<data} { {<data} {


'OUTPUTHTML': function(context) { 'OUTPUTHTML': function(context) {
context.data('$html').find('iframe, img, script').remove(); var $html = context.data('$html');
return context.data('$html').prop('outerHTML') $html.find('iframe, img, script').remove();

var endIteration = document.createElement('script');
var inject = function() {
location.search = location.search.replace( /([?&]iter=)(\d+)/, function(all, start, index) {
return start + ++index
}).replace(/([?&]perf=)([^&]*)/, function(all, start, value) {
return start + JSON.stringify(Mobify.timing.points);
});
}
endIteration.textContent = '(' + inject + ')()';
context.data('$body')[0].appendChild(endIteration);

return $html.prop('outerHTML')
} }


} {/data} } {/data}
12 changes: 12 additions & 0 deletions test/integration/performance/03.beyondtherack-home.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
<script src="comradeLaikaRocketDog.js"></script>
<img src="comradeLaikaRocketDog.jpg">
<iframe src="comradeLaikaRocketDog.jpg"></iframe>

</body>
</head>

Large diffs are not rendered by default.

@@ -0,0 +1,9 @@
{
"name": "test/03.beyondtherack-home",
"api": "1.1",
"build_directory": "bld",
"plugins": [],
"exclude": [
"*.tmpl"
]
}
23 changes: 23 additions & 0 deletions test/integration/performance/03.beyondtherack-home/src/mobify.konf
@@ -0,0 +1,23 @@
{>"/base/lib/base_konf.konf"/}
{<tmpl}{/tmpl}
{<data} {

'OUTPUTHTML': function(context) {
var $html = context.data('$html');
$html.find('iframe, img, script').remove();

var endIteration = document.createElement('script');
var inject = function() {
location.search = location.search.replace( /([?&]iter=)(\d+)/, function(all, start, index) {
return start + ++index
}).replace(/([?&]perf=)([^&]*)/, function(all, start, value) {
return start + JSON.stringify(Mobify.timing.points);
});
}
endIteration.textContent = '(' + inject + ')()';
context.data('$body')[0].appendChild(endIteration);

return $html.prop('outerHTML')
}

} {/data}
@@ -0,0 +1,10 @@
{>base_smartphone/}

{<body}
{#content}

{image}

{/content}

{/body}
@@ -0,0 +1,5 @@
{#categorynav}

{nav}

{/categorynav}
@@ -0,0 +1,68 @@
{#footer}
{^isCart}
{?isLoggedIn}

<div class="x-backtotop">
<a id="x-backtotop-link" href="#"><span>Back to Top</span></a>
</div>

<nav class="x-category-nav">
{>_categorynav/}
</nav>

{?isCart}

{:else}

<div class="x-row">
<div class="x-account">
{account}
</div>
<div class="x-cart">
<a href="/bag/show">
{?checkoutButtonNum}
<span class="x-checkout-num">
{checkoutButtonNum}
</span>
{/checkoutButtonNum}
</a>
</div>
</div>

{/isCart}

{/isLoggedIn}

<nav id="x-bottom-nav">
<ul>
{#footerLinks}
<li>
{.}
</li>
{/footerLinks}
{?isLoggedIn}
<li>{signOut}</li>
{/isLoggedIn}
</ul>
</nav>
{/isCart}

<div class="x-row">
<!-- <div id="x-full-site"><a onclick="return Mobify.desktop();">View full site</a></div> -->
<div id="x-copyright">{?isLoggedIn}{copyright}{:else}{content.copyright}{/isLoggedIn}</div>
</div>

{shoppingbag}
{%script}
(function($) {
// Scroll to top.
$('#x-backtotop-link').bind('click', function(e) {
e.stopPropagation();
e.preventDefault();
$('body').animate({scrollTop: 1}, 200);
return false;
});
})(Mobify.$);
{/script}

{/footer}
@@ -0,0 +1,86 @@
{#header}
<ul id="x-header-bar">
<li class="x-logo">
<a href="/">
<img src="{config.configDir}i/logo{HD}.png" alt="Beyond the Rack" />
</a>
</li>

{?isLoggedIn}

{?isCart}
{?content.checkout}

<li class="x-icon x-modify">
<a href="/bag/show">Modify cart</a>
</li>

{:else}

<li class="x-icon x-checkout">
<a href="/bag/checkout">Checkout now</a>
</li>

{/content.checkout}

{:else}

<li class="x-icon x-nav">
<a href="#">Nav</a>
</li>

<li class="x-icon x-account {?isAccountPage}x-active{/isAccountPage}">
{account}
</li>
<li class="x-icon x-cart">
<a href="/bag/show">
{?checkoutButtonNum}
<span class="x-checkout-num">
{checkoutButtonNum}
</span>
{/checkoutButtonNum}
</a>
</li>

{/isCart}

{:else}

{?content.login}

<li class="x-icon x-signup">
<a href="/auth/register?r=">Sign up here</a>
</li>

{/content.login}

{?content.register}

<li class="x-icon x-signup">
<a href="/auth/login?r=">Sign in here</a>
</li>

{/content.register}

{/isLoggedIn}
</ul>
{?isLoggedIn}
<nav id="x-top-nav" class="x-category-nav">
{>_categorynav/}
</nav>
{/isLoggedIn}

{%script}
(function($) {
// Toggle menu

$('li.x-nav a').click(function() {
$('body').toggleClass('x-nav-active').addClass('x-animate');
$('li.x-nav').toggleClass('x-active');
//$('#x-top-nav').slideToggle();
$('#x-top-nav').toggleClass('x-active');
return false;
});
})(Mobify.$);
{/script}
{/header}
@@ -0,0 +1,23 @@
{%script}
/* GA order tracking */
(function($) {
var text = $('pre').text()
, orderId = /order no. ([0-9]+)/.exec(text)[1]
, taxRe = /[GQ]ST.*?\$\s*([0-9]+\.[0-9]+)/g
, matchTotal = /Total.*\$\s*([0-9]+\.[0-9]+)/.exec(text)
, tax = 0
, total = 0
, match;

while (match = taxRe.exec(text)) {
tax += +match[1] || 0;
}

if (matchTotal) total = matchTotal[1];

Mobify.analytics = Mobify.analytics || {};
Mobify.analytics.ga = Mobify.analytics.ga || [];
Mobify.analytics.ga.push(['_addTrans', orderId, 'BTR', total, tax], ['_trackTrans']);

})(Mobify.$);
{/script}

0 comments on commit eceb559

Please sign in to comment.