Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java

raw symbols SCIP
1 package org.mozilla.javascript.benchmarks;
2
3 import org.junit.AfterClass;
4 import org.junit.Test;
5 import org.mozilla.javascript.Context;
6 import org.mozilla.javascript.tools.shell.Global;
7
8 import java.io.*;
9 import java.util.HashMap;
10
11 public class SunSpiderBenchmark
12 {
13 public static final String TEST_SRC = "sunspider-0.9.1/run.js";
14
15 private static final HashMap<Integer, String> results = new HashMap<Integer, String>();
16
17 @AfterClass
18 public static void writeResults()
19 throws IOException
20 {
21 PrintWriter out = new PrintWriter(
22 new FileWriter(new File(System.getProperty("rhino.benchmark.report"), "sunspider.csv"))
23 );
24 // Hard code the opt levels for now -- we will make it more generic when we need to
25 out.println("Optimization 0,Optimization 9");
26 out.println(results.get(0) + ',' + results.get(9));
27 out.close();
28 }
29
30 private void runTest(int optLevel)
31 throws IOException
32 {
33 FileInputStream srcFile = new FileInputStream(TEST_SRC);
34 InputStreamReader rdr = new InputStreamReader(srcFile, "utf8");
35
36 try {
37 Context cx = Context.enter();
38 cx.setLanguageVersion(Context.VERSION_1_8);
39 cx.setOptimizationLevel(optLevel);
40 Global root = new Global(cx);
41 root.put("RUN_NAME", root, "SunSpider-" + optLevel);
42 Object result = cx.evaluateReader(root, rdr, TEST_SRC, 1, null);
43 results.put(optLevel, result.toString());
44 } finally {
45 rdr.close();
46 srcFile.close();
47 }
48 }
49
50 @Test
51 public void testOptLevel9()
52 throws IOException
53 {
54 runTest(9);
55 }
56
57 @Test
58 public void testOptLevel0()
59 throws IOException
60 {
61 runTest(0);
62 }
63 }