Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/benchmarks/V8Benchmark.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 V8Benchmark
12 {
13 public static final String TEST_SRC = "v8-benchmarks-v6/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"), "v8benchmark.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
34 FileInputStream srcFile = new FileInputStream(TEST_SRC);
35 InputStreamReader rdr = new InputStreamReader(srcFile, "utf8");
36
37 try {
38 Context cx = Context.enter();
39 cx.setLanguageVersion(Context.VERSION_1_8);
40 cx.setOptimizationLevel(optLevel);
41 Global root = new Global(cx);
42 root.put("RUN_NAME", root, "V8-Benchmark-" + optLevel);
43 Object result = cx.evaluateReader(root, rdr, TEST_SRC, 1, null);
44 results.put(optLevel, result.toString());
45 } finally {
46 rdr.close();
47 srcFile.close();
48 }
49 }
50
51 @Test
52 public void testOptLevel9()
53 throws IOException
54 {
55 runTest(9);
56 }
57
58 @Test
59 public void testOptLevel0()
60 throws IOException
61 {
62 runTest(0);
63 }
64 }