From f04c4e65d07b3333ff0e55331ded2fae3ff4b721 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Mon, 9 Jun 2014 16:27:32 -0700 Subject: [PATCH] feat(benchmark): add automatic gc before each test Also included is a script to launch Chrome Canary with the appropriate flag to enable manual garbage collection. --- benchmark/launch_chrome.sh | 8 ++++++++ benchmark/web/bp.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100755 benchmark/launch_chrome.sh diff --git a/benchmark/launch_chrome.sh b/benchmark/launch_chrome.sh new file mode 100755 index 000000000..466b49c24 --- /dev/null +++ b/benchmark/launch_chrome.sh @@ -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 diff --git a/benchmark/web/bp.js b/benchmark/web/bp.js index c81c20366..ca8d846a4 100644 --- a/benchmark/web/bp.js +++ b/benchmark/web/bp.js @@ -35,7 +35,7 @@ window.addEventListener('DOMContentLoaded', function() { btn.innerText = "Loop"; var running = false; btn.addEventListener('click', loopBenchmark); - + container.appendChild(btn); function loopBenchmark() { @@ -50,10 +50,10 @@ window.addEventListener('DOMContentLoaded', function() { if (running) { window.requestAnimationFrame(function() { if (running) runBenchmarkSteps(loopB); - }); + }); } }; - loopB(); + loopB(); }); } } @@ -68,7 +68,7 @@ window.addEventListener('DOMContentLoaded', function() { runBenchmarkSteps(function() { onceBtn.innerText = "Once"; }); - }); + }); }); }); container.appendChild(onceBtn); @@ -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; @@ -109,7 +112,7 @@ window.addEventListener('DOMContentLoaded', function() { } var timesPerAction = {}; - + var NUM_SAMPLES = 10; function calcStats(times) { var iH = '';