Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
receiver: only run the benchmark when the page is visible
Browse files Browse the repository at this point in the history
Otherwise, the measured number of FPS can be pretty low.
  • Loading branch information
vincentbernat committed Apr 21, 2015
1 parent faef5a5 commit 03c20d0
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app/scripts/receiver/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,25 @@ define('benchmark', (function(window, $) {
}
}

return {
done: function(cb) {
var done = function(cb) {
var run = function() {

// Only run the benchmark if the page is not hidden. If the
// visibility API is unavailable, the document will never be
// considered hidden.
window.document.removeEventListener('visibilitychange', run, false);
if (window.document.hidden === true) {
window.document.addEventListener('visibilitychange', run, false);
return;
}
window.document.removeEventListener('visibilitychange', run, false);

// Setup some global variables
benchmark = $('.benchmark');
stageWidth = benchmark.width();
stageHeight = benchmark.height();

// Create and start animate particles
createParticles();
prevTime = window.performance.now();
animate();
Expand All @@ -115,6 +128,7 @@ define('benchmark', (function(window, $) {
particles[i].destroy();
}
particles = [];
benchmark.remove();

// Record the number of frames displayed
var fps = frames / duration * 1000;
Expand All @@ -124,10 +138,15 @@ define('benchmark', (function(window, $) {
}

// Call callback
benchmark.remove();
cb();
}, duration);
}
};

run();
};

return {
done: done
};

})(window, Zepto));

0 comments on commit 03c20d0

Please sign in to comment.