Revision: 3785
Author: mikesamuel
Date: Wed Oct 7 12:53:10 2009
Log: Benchmark HTML/XML rendering.
http://codereview.appspot.com/124119
Emits benchmark data to the historical logs in the same way
DomParserTest does for parsing.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=3785
Modified:
/trunk/tests/com/google/caja/parser/html/NodesTest.java
=======================================
--- /trunk/tests/com/google/caja/parser/html/NodesTest.java Thu Jul 23
09:16:30 2009
+++ /trunk/tests/com/google/caja/parser/html/NodesTest.java Wed Oct 7
12:53:10 2009
@@ -14,9 +14,11 @@
package com.google.caja.parser.html;
-import junit.framework.TestCase;
-
-public class NodesTest extends TestCase {
+import com.google.caja.util.CajaTestCase;
+
+import org.w3c.dom.Element;
+
+public class NodesTest extends CajaTestCase {
public final void testDecode() throws Exception {
assertEquals(Nodes.decode("1 < 2 && 4 > "3""),
"1 < 2 && 4 > \"3\"");
@@ -83,4 +85,20 @@
assertEquals("&;", Nodes.decode("&;"));
assertEquals("&bogus;", Nodes.decode("&bogus;"));
}
-}
+
+ public final void testRenderSpeed() throws Exception {
+ Element doc = html(fromResource("amazon.com.html"));
+ benchmark(100, doc); // prime the JIT
+ Thread.sleep(250); // Let the JIT kick-in.
+ int microsPerRun = benchmark(250, doc);
+ // See extractVarZ in "tools/dashboard/dashboard.pl".
+ System.out.println(
+ " VarZ:" + getClass().getName() + ".msPerRun=" + microsPerRun);
+ }
+
+ private int benchmark(int nRuns, Element el) {
+ long t0 = System.nanoTime();
+ for (int i = nRuns; --i >= 0;) { Nodes.render(el); }
+ return (int) ((((double) (System.nanoTime() - t0)) / nRuns) / 1e3);
+ }
+}