Revision: 4294
Author: jasvir
Date: Tue Oct 5 10:50:47 2010
Log: Enable benchmarking of ES53 code on macro and micro benchmarks
http://codereview.appspot.com/2365042
* Adds a cajole and run in ES53 mode to BenchmarkRunner
* Removes the running of benchmarks wrapped in function closures
[email protected]
http://code.google.com/p/google-caja/source/detail?r=4294
Modified:
/trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java
=======================================
--- /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java Mon
Jul 12 16:56:22 2010
+++ /trunk/tests/com/google/caja/demos/benchmarks/BenchmarkRunner.java Tue
Oct 5 10:50:47 2010
@@ -71,7 +71,6 @@
public final void testLoopSum() throws Exception {
runBenchmark("loop-sum.js");
}
-
/**
* Runs the given benchmark
@@ -82,30 +81,21 @@
*/
private void runBenchmark(String filename) throws Exception {
double uncajoledTime = runUncajoled(filename);
- double cajitaTime = runCajoled(filename, false, false);
- double valijaTime = runCajoled(filename, true, false);
- double valijaWrappedTime = runCajoled(filename, true, true);
- double cajitaWrappedTime = runCajoled(filename, false, true);
+ double cajitaTime = runCajoledLegacy(filename, false);
+ double valijaTime = runCajoledLegacy(filename, true);
+ double es53Time = runCajoledES53(filename);
varz(getName(), "uncajoled", "time", uncajoledTime);
varz(getName(), "valija", "time", valijaTime);
varz(getName(), "cajita", "time", cajitaTime);
-
+ varz(getName(), "es53", "time", es53Time);
+
varz(getName(), "valija", "timeratio",
valijaTime < 0 ? -1 : valijaTime / uncajoledTime);
varz(getName(), "cajita", "timeratio",
cajitaTime < 0 ? -1 : cajitaTime / uncajoledTime);
-
- // We rename the test here because wrapping globals is an optimization
- // that changes the benchmark -- albeit a trivial one that is easy for
- // developers to perform on their own code.
- varz(getName() + "WrapGlobals", "valija", "time", valijaWrappedTime);
- varz(getName() + "WrapGlobals", "cajita", "time", cajitaWrappedTime);
-
- varz(getName() + "WrapGlobals", "valija", "timeratio",
- valijaWrappedTime < 0 ? -1 : valijaWrappedTime / uncajoledTime);
- varz(getName() + "WrapGlobals", "cajita", "timeratio",
- cajitaWrappedTime < 0 ? -1 : cajitaWrappedTime / uncajoledTime);
+ varz(getName(), "es53", "timeratio",
+ es53Time < 0 ? -1 : es53Time / uncajoledTime);
}
private void varz(String name, String lang, String feature, double
value) {
@@ -113,10 +103,6 @@
"VarZ:benchmark." + name + "." + feature + "." + lang +
".nodebug.rhino.cold=" + value);
}
-
- private String wrapGlobals(String nakedJS) {
- return "(function() {" + nakedJS + "})();";
- }
private double runUncajoled(String filename) throws Exception {
Number elapsed = (Number) RhinoTestBed.runJs(
@@ -127,14 +113,11 @@
return elapsed.doubleValue();
}
- private double runCajoled(String filename, boolean valija,
- boolean wrapGlobals) throws Exception {
+ private double runCajoledLegacy(String filename, boolean valija) throws
Exception {
PluginMeta meta = new PluginMeta();
MessageQueue mq = new SimpleMessageQueue();
PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
- CharProducer src = wrapGlobals ?
- fromString(wrapGlobals(plain(fromResource(filename)))):
- fromString(plain(fromResource(filename)));
+ CharProducer src = fromString(plain(fromResource(filename)));
pc.addInput(
valija ? BenchmarkUtils.addUseCajitaDirective(js(src)) : js(src),
is.getUri());
@@ -143,8 +126,7 @@
}
String cajoledJs = render(pc.getJavascript());
System.err.println("-- Cajoled:" + filename +
- "(wrapped: " + wrapGlobals +
- ", valija:" + valija + ") --\n" + cajoledJs + "\n---\n");
+ "(valija:" + valija + ") --\n" + cajoledJs + "\n---\n");
Number elapsed = (Number) RhinoTestBed.runJs(
new Executor.Input(getClass(),
"../../../../../js/json_sans_eval/json_sans_eval.js"),
@@ -175,4 +157,41 @@
"elapsed"));
return elapsed.doubleValue();
}
-}
+
+ private double runCajoledES53(String filename) throws Exception {
+ PluginMeta meta = new PluginMeta();
+ meta.setEnableES53(true);
+ MessageQueue mq = new SimpleMessageQueue();
+ PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
+ CharProducer src = fromString(plain(fromResource(filename)));
+ pc.addInput(js(src), is.getUri());
+
+ if (!pc.run()) {
+ return -1;
+ }
+ String cajoledJs = render(pc.getJavascript());
+ System.err.println("-- Cajoled:" + filename +
+ "(es53: true" + ") --\n" + cajoledJs + "\n---\n");
+ Number elapsed = (Number) RhinoTestBed.runJs(
+ new Executor.Input(getClass(),
+ "../../../../../js/json_sans_eval/json_sans_eval.js"),
+ new Executor.Input(getClass(), "../../es53.js"),
+ new Executor.Input(
+ // Set up the imports environment.
+ ""
+ + "var imports =
___.copy(___.whitelistAll(___.sharedImports));"
+ + "imports.onerror = ___.markFunc(function(x){ return true;
});"
+ + "___.setLogFunc(imports.onerror);"
+ + "imports.benchmark = ___.whitelistAll({startTime:0});"
+
+ "___.getNewModuleHandler().setImports(___.whitelistAll(imports));"
+
+ + "imports.benchmark.startTime = new Date();",
+ "benchmark-container"),
+ new Executor.Input(cajoledJs, getName()),
+ new Executor.Input(
+ "(new Date() - imports.benchmark.startTime)",
+ "elapsed"));
+ return elapsed.doubleValue();
+ }
+
+}