File tree 2 files changed +56
-0
lines changed 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ var results = [ ] ;
2
+
3
+ var Context = function ( ) {
4
+ this . foo = 'bar' ;
5
+ } ;
6
+
7
+ Context . prototype . testArgs = function ( ) {
8
+ if ( arguments [ 0 ] ) {
9
+ results . push ( true ) ;
10
+ }
11
+ if ( arguments [ 1 ] ) {
12
+ results . push ( true ) ;
13
+ }
14
+ if ( arguments [ 2 ] ) {
15
+ results . push ( true ) ;
16
+ }
17
+ if ( arguments [ 3 ] ) {
18
+ results . push ( true ) ;
19
+ }
20
+ } ;
21
+
22
+ var testPerf = function ( ) {
23
+ var context = new Context ( ) ;
24
+ context . testArgs ( ) ;
25
+ context . testArgs ( 1 ) ;
26
+ context . testArgs ( 1 , 2 ) ;
27
+ context . testArgs ( 1 , 2 , 3 ) ;
28
+ context . testArgs ( 1 , 2 , 3 , 4 ) ;
29
+ } ;
Original file line number Diff line number Diff line change
1
+ package com .winterbe .java8 ;
2
+
3
+ import jdk .nashorn .api .scripting .NashornScriptEngine ;
4
+
5
+ import javax .script .ScriptEngineManager ;
6
+ import javax .script .ScriptException ;
7
+ import java .util .concurrent .TimeUnit ;
8
+
9
+ /**
10
+ * @author Benjamin Winterberg
11
+ */
12
+ public class Nashorn10 {
13
+
14
+ public static void main (String [] args ) throws ScriptException , NoSuchMethodException {
15
+ NashornScriptEngine engine = (NashornScriptEngine ) new ScriptEngineManager ().getEngineByName ("nashorn" );
16
+ engine .eval ("load('res/nashorn10.js')" );
17
+
18
+ long t0 = System .nanoTime ();
19
+
20
+ for (int i = 0 ; i < 100000 ; i ++) {
21
+ engine .invokeFunction ("testPerf" );
22
+ }
23
+
24
+ long took = System .nanoTime () - t0 ;
25
+ System .out .format ("Elapsed time: %d ms" , TimeUnit .NANOSECONDS .toMillis (took ));
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments