Merge "Change BenchmarkExecutor to reduce memory stress."
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/BenchmarkExecutor.java b/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/BenchmarkExecutor.java
index 9a74bb3..c3078f3 100644
--- a/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/BenchmarkExecutor.java
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/BenchmarkExecutor.java
@@ -16,7 +16,6 @@
 package com.google.gwt.benchmark.framework.shared;
 
 import com.google.gwt.benchmark.collection.shared.CollectionFactory;
-import com.google.gwt.benchmark.collection.shared.JavaScriptArray;
 import com.google.gwt.benchmark.collection.shared.JavaScriptArrayNumber;
 
 /**
@@ -50,23 +49,20 @@
     double minimalEnd = startMs + minimalTime;
 
     int runs = 0;
-    JavaScriptArray<Object> array = CollectionFactory.create();
     JavaScriptArrayNumber times = CollectionFactory.createNumber();
 
     while (runs <= minimalRuns || performance.now() < minimalEnd) {
       benchmark.setup();
       double currentMs = performance.now();
       Object result = benchmark.run();
-      array.push(result);
       times.push(performance.now() - currentMs);
+      Util.disableOpt(result);
       runs++;
       benchmark.tearDown();
     }
 
     double tookMs = performance.now() - startMs;
 
-    // Keep GWT compiler / JavaScript engine from removing code
-    Util.disableOpt(array);
 
     BenchmarkResult benchmarkResult = BenchmarkResultFactory.create();
     benchmarkResult.setName(benchmark.getName());
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/Util.java b/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/Util.java
index cb19491..48a1bea 100644
--- a/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/Util.java
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/framework/shared/Util.java
@@ -33,10 +33,11 @@
     }
   }
 
+  /**
+   * Placing results of a benchmark on global window should effectly disable any bad optimizations
+   * since the field could be read by another script that might get loaded later.
+   */
   private static native void disableOptGwt(Object o) /*-{
-    if(!$wnd.__private_disableOpt) {
-      $wnd.__private_disableOpt = function(){};
-    }
-    $wnd.__private_disableOpt(o);
+    $wnd.__private_disableOpt = o;
   }-*/;
 }