Change BenchmarkExecutor to reduce memory stress.

BenchmarkExecutor was retaining all returns from 'run'
to disable potential optimizations.
This was problematic because as GWT is optimized and
performed better, it produces more output which reduces
in turn the performance very significantly, especially
if the returned object is big (which is in most of the
times).

Changed the executor so it no longer keeps all results,
instead only the last result is preserved and stored in a
global variable. This significantly changes the results of
the many benchmarks.

Change-Id: If2b4ba5150828963f251a93e30f7cca0af0c595f
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;
   }-*/;
 }