Permalink
Browse files

Perf tests dev, continued

  • Loading branch information...
1 parent 1120389 commit eceb559b660d397223091fd5984f96004319f503 Roman Rudenko committed Jul 18, 2012
Showing with 1,228 additions and 59 deletions.
  1. +8 −8 test/integration/analyzeDeltas.js
  2. +34 −15 test/integration/mobifyjs.coffee
  3. +1 −0 test/integration/performance/02.basicResource/bld/mobify.js
  4. +15 −2 test/integration/performance/02.basicResource/src/mobify.konf
  5. +12 −0 test/integration/performance/03.beyondtherack-home.html
  6. +1 −0 test/integration/performance/03.beyondtherack-home/bld/mobify.js
  7. +9 −0 test/integration/performance/03.beyondtherack-home/project.json
  8. +23 −0 test/integration/performance/03.beyondtherack-home/src/mobify.konf
  9. +10 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/404.tmpl
  10. +5 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/_categorynav.tmpl
  11. +68 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/_footer.tmpl
  12. +86 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/_header.tmpl
  13. +23 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/_record_sale_js.tmpl
  14. +24 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/accountinfo.tmpl
  15. +42 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/base.tmpl
  16. +14 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/base_smartphone.tmpl
  17. +47 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/base_tablet.tmpl
  18. +90 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/cart.tmpl
  19. +15 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/contact.tmpl
  20. +9 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/default.tmpl
  21. +95 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/events.tmpl
  22. +15 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/faq.tmpl
  23. +5 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/forgotPassword.tmpl
  24. +16 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/inviteafriend.tmpl
  25. +38 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/landing.tmpl
  26. +8 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/orderConfirmation.tmpl
  27. +272 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/pdp.tmpl
  28. +145 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/productlist.tmpl
  29. +9 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/recommend.tmpl
  30. +29 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/register.tmpl
  31. +9 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/sizechart.tmpl
  32. +47 −0 test/integration/performance/03.beyondtherack-home/src/tmpl/trackorders.tmpl
  33. +4 −34 test/integration/run-tests.js
@@ -24,20 +24,20 @@
'infinity': 1.96
};
- window.analyzeDeltas = function(timingPoints) {
+ module.exports = function(timingPoints) {
var deltas = [];
timingPoints.forEach(function(run) {
run.forEach(function(entry, i) {
- var lastEntry = i ? run[i-1] : entry;
- var delta = entry[0] - lastEntry[0];
+ var lastEntry = run[(run.length + i-1) % run.length];
+ var delta = Math.abs(entry[0] - lastEntry[0]);
deltas[i] = deltas[i] || [];
- deltas[i].name = entry[1];
+ deltas[i].name = i ? entry[1] : 'Total';
deltas[i].push(delta / 1e3);
})
});
- deltas.forEach(function(delta) {
+ return deltas.map(function(delta) {
delta.mean = getMean(delta);
// sample variance (estimate of the population variance)
delta.variance = delta.reduce(
@@ -57,8 +57,8 @@
// relative margin of error
delta.rme = (delta.moe / delta.mean) * 100 || 0;
- log(' ' + delta.name + ', avg ' + (delta.mean * 1e3).toFixed(2) + 'ms \xb1'
- + delta.rme.toFixed(2) + '%');
- });
+ return ' ' + delta.name + ', avg ' + (delta.mean * 1e3).toFixed(2) + 'ms +/-'
+ + delta.rme.toFixed(2) + '%';
+ }).join('\n');
};
})();
@@ -17,8 +17,10 @@ Injector = require '../../src/injector.coffee'
{Project} = require '../../src/project.coffee'
Preview = require '../../src/preview.coffee'
Scaffold = require '../../src/scaffold.coffee'
+analyzeDeltas = require './analyzeDeltas.js'
PORT = { STATIC: 1341, TAG: 1342, PREVIEW: 8080 }
+PERF_ITERATIONS = 50
requestLog = [];
logRequests = () ->
result = requestLog.join('\n')
@@ -39,15 +41,35 @@ program
start = (mode) ->
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 = new Connect()
.use(Connect.query())
+ .use(Connect.cookieParser())
+ .use(Connect.session({ secret: "keyboard cat" }))
.use('/', (req, res, next) ->
- return next() if req.query.tests or req.url != '/'
- res.writeHead(302, {Location: req.url + '?mode=' + mode + '&tests=' + tests.join('+')})
- res.end()
+ if !req.query.tests and req.url == '/'
+ res.writeHead(302, {Location: req.url + "?mode=#{mode}&tests=" + tests.join('+')})
+ 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.middleware.logger((request, result) ->
@@ -65,17 +87,14 @@ start = (mode) ->
)
)
.use('/end', (req, res) ->
- res.end logRequests()
+ res.end(logRequests())
)
- .use('/submit', (req, res) ->
- body = ''
- req.on('data', (data) ->
- body += data;
- )
- req.on('end', () ->
- console.log(body)
- res.end
- )
+ .use('/done', (req, res) ->
+ for key in tests
+ results = JSON.parse('[' + req.session[key].split('\n').join(',') + '0]')
+ results.pop()
+ res.write(key + '\n' + analyzeDeltas(results) + '\n')
+ res.end()
)
.use('/start', (req, res) ->
logRequests()
@@ -86,7 +105,7 @@ start = (mode) ->
project = Project.load "test/integration/#{mode}#{target}/project.json"
project.build_directory = "test/integration/#{mode}#{target}/bld"
- project.build({ test: true, }, (err) ->
+ project.build({ test: true, production:false }, (err) ->
if err
error = "Failed to build #{target}. Error: #{err}"
console.log(error)
Oops, something went wrong.
@@ -3,8 +3,21 @@
{<data} {
'OUTPUTHTML': function(context) {
- context.data('$html').find('iframe, img, script').remove();
- return context.data('$html').prop('outerHTML')
+ 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,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>
Oops, something went wrong.
@@ -0,0 +1,9 @@
+{
+ "name": "test/03.beyondtherack-home",
+ "api": "1.1",
+ "build_directory": "bld",
+ "plugins": [],
+ "exclude": [
+ "*.tmpl"
+ ]
+}
@@ -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}
Oops, something went wrong.

0 comments on commit eceb559

Please sign in to comment.