14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.performance;
27
28 import java.io.OutputStream;
29 import java.util.concurrent.Callable;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.Future;
32 import java.util.concurrent.TimeUnit;
33 import java.util.concurrent.TimeoutException;
34 import jdk.nashorn.internal.runtime.Context;
35 import jdk.nashorn.internal.runtime.ScriptFunction;
36 import jdk.nashorn.internal.runtime.ScriptObject;
37 import jdk.nashorn.internal.runtime.ScriptRuntime;
38
39 /**
40 *
41 * @author Pavel Stepanov
42 */
43 public class PerformanceWrapper extends jdk.nashorn.tools.Shell {
44
45 int _numberOfIterations;
46 int _runsPerIteration;
47
48 protected void runCompileOnlyTest(final String name, final int numberOfIterations, final int runsPerIteration, final String testURL) throws Throwable {
49 final String[] args = { name, "--compile-only=true", "-dump-on-error", "--", testURL };
50
51 final long[] times = new long[numberOfIterations + 1];
52 times[0] = System.nanoTime(); // Calendar.getInstance().getTimeInMillis();
53
54 for (int iteration = 1; iteration <= numberOfIterations; iteration++) {
55 for (int i = 0; i < runsPerIteration; i++) {
56 run(System.in, System.out, System.err, args);
72 }
73
74
75 protected void runExecuteOnlyTest(final String name, final int numberOfIterations, final int runsPerIteration, final String testURL, final OutputStream out, final OutputStream err, String[] newargs) throws Throwable {
76 String[] args=new String[newargs.length+1];
77 System.arraycopy(newargs, 0, args, 1, newargs.length);
78 args[0]=name;
79
80 // for (String s: args)
81 // System.out.println(s);
82
83 _numberOfIterations = numberOfIterations;
84 _runsPerIteration = runsPerIteration;
85 run(System.in, out, err, args);
86 // System.out.println("overridableRun finished");
87 }
88
89 @Override
90 protected Object apply(final ScriptFunction target, final Object self) {
91 if (_runsPerIteration == 0 && _numberOfIterations == 0) {
92 final ScriptObject global = jdk.nashorn.internal.runtime.Context.getGlobal();
93 final ScriptFunction _target = target;
94 final Object _self = self;
95
96 class MyThread implements Callable<Object> {
97 @Override
98 public Object call() {
99 Context.setGlobal(global);
100 //just execute and return script is sufficient
101 final Object scriptRuntimeApplyResult = ScriptRuntime.apply(_target, _self);
102 return scriptRuntimeApplyResult;
103 }
104 }
105
106 final java.util.concurrent.ThreadPoolExecutor executor = new java.util.concurrent.ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, new java.util.concurrent.ArrayBlockingQueue<Runnable>(10));
107 final MyThread myThread = new MyThread();
108 // executor.execute(myThread);
109 Object result;
110 Future<?> futureResult = null;
111
112 try {
|
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.performance;
27
28 import java.io.OutputStream;
29 import java.util.concurrent.Callable;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.Future;
32 import java.util.concurrent.TimeUnit;
33 import java.util.concurrent.TimeoutException;
34 import jdk.nashorn.internal.objects.Global;
35 import jdk.nashorn.internal.runtime.Context;
36 import jdk.nashorn.internal.runtime.ScriptFunction;
37 import jdk.nashorn.internal.runtime.ScriptRuntime;
38
39 /**
40 *
41 * @author Pavel Stepanov
42 */
43 public class PerformanceWrapper extends jdk.nashorn.tools.Shell {
44
45 int _numberOfIterations;
46 int _runsPerIteration;
47
48 protected void runCompileOnlyTest(final String name, final int numberOfIterations, final int runsPerIteration, final String testURL) throws Throwable {
49 final String[] args = { name, "--compile-only=true", "-dump-on-error", "--", testURL };
50
51 final long[] times = new long[numberOfIterations + 1];
52 times[0] = System.nanoTime(); // Calendar.getInstance().getTimeInMillis();
53
54 for (int iteration = 1; iteration <= numberOfIterations; iteration++) {
55 for (int i = 0; i < runsPerIteration; i++) {
56 run(System.in, System.out, System.err, args);
72 }
73
74
75 protected void runExecuteOnlyTest(final String name, final int numberOfIterations, final int runsPerIteration, final String testURL, final OutputStream out, final OutputStream err, String[] newargs) throws Throwable {
76 String[] args=new String[newargs.length+1];
77 System.arraycopy(newargs, 0, args, 1, newargs.length);
78 args[0]=name;
79
80 // for (String s: args)
81 // System.out.println(s);
82
83 _numberOfIterations = numberOfIterations;
84 _runsPerIteration = runsPerIteration;
85 run(System.in, out, err, args);
86 // System.out.println("overridableRun finished");
87 }
88
89 @Override
90 protected Object apply(final ScriptFunction target, final Object self) {
91 if (_runsPerIteration == 0 && _numberOfIterations == 0) {
92 final Global global = jdk.nashorn.internal.runtime.Context.getGlobal();
93 final ScriptFunction _target = target;
94 final Object _self = self;
95
96 class MyThread implements Callable<Object> {
97 @Override
98 public Object call() {
99 Context.setGlobal(global);
100 //just execute and return script is sufficient
101 final Object scriptRuntimeApplyResult = ScriptRuntime.apply(_target, _self);
102 return scriptRuntimeApplyResult;
103 }
104 }
105
106 final java.util.concurrent.ThreadPoolExecutor executor = new java.util.concurrent.ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, new java.util.concurrent.ArrayBlockingQueue<Runnable>(10));
107 final MyThread myThread = new MyThread();
108 // executor.execute(myThread);
109 Object result;
110 Future<?> futureResult = null;
111
112 try {
|