Skip to content

Commit

Permalink
feat(benchmark): add automatic gc before each test
Browse files Browse the repository at this point in the history
Also included is a script to launch Chrome Canary with the appropriate flag to
enable manual garbage collection.

Closes dart-archive#1133
  • Loading branch information
jeffbcross authored and Diana Salsbury committed Jul 16, 2014
1 parent fb4ae8b commit 3fe6a58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions benchmark/launch_chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

platform=`uname`
if [[ "$platform" == 'Linux' ]]; then
`google-chrome --js-flags="--expose-gc"`
elif [[ "$platform" == 'Darwin' ]]; then
`/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --js-flags="--expose-gc"`
fi
13 changes: 8 additions & 5 deletions benchmark/web/bp.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ window.addEventListener('DOMContentLoaded', function() {
btn.innerText = "Loop";
var running = false;
btn.addEventListener('click', loopBenchmark);

container.appendChild(btn);

function loopBenchmark() {
Expand All @@ -50,10 +50,10 @@ window.addEventListener('DOMContentLoaded', function() {
if (running) {
window.requestAnimationFrame(function() {
if (running) runBenchmarkSteps(loopB);
});
});
}
};
loopB();
loopB();
});
}
}
Expand All @@ -68,7 +68,7 @@ window.addEventListener('DOMContentLoaded', function() {
runBenchmarkSteps(function() {
onceBtn.innerText = "Once";
});
});
});
});
});
container.appendChild(onceBtn);
Expand Down Expand Up @@ -99,6 +99,9 @@ window.addEventListener('DOMContentLoaded', function() {
// Run all the steps;
var times = {};
window.benchmarkSteps.forEach(function(bs) {
if (typeof window.gc === 'function') {
window.gc();
}
var startTime = numMilliseconds();
bs.fn();
times[bs.name] = numMilliseconds() - startTime;
Expand All @@ -109,7 +112,7 @@ window.addEventListener('DOMContentLoaded', function() {
}

var timesPerAction = {};

var NUM_SAMPLES = 10;
function calcStats(times) {
var iH = '';
Expand Down

0 comments on commit 3fe6a58

Please sign in to comment.