-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master-upstream' into better-type-support
- Loading branch information
Showing
65 changed files
with
7,102 additions
and
1,316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
benchmarks/org/mozilla/javascript/benchmarks/PropertyBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.mozilla.javascript.benchmarks; | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Function; | ||
import org.mozilla.javascript.ScriptRuntime; | ||
import org.mozilla.javascript.Scriptable; | ||
import org.mozilla.javascript.ScriptableObject; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
public class PropertyBenchmark { | ||
@State(Scope.Thread) | ||
public static class PropertyState { | ||
Context cx; | ||
Scriptable scope; | ||
|
||
Function create; | ||
Function createFieldByField; | ||
Function getName; | ||
Function check; | ||
|
||
Object object; | ||
|
||
@Setup(Level.Trial) | ||
public void setup() throws IOException { | ||
cx = Context.enter(); | ||
cx.setOptimizationLevel(9); | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
scope = cx.initStandardObjects(); | ||
|
||
try (FileReader rdr = | ||
new FileReader("testsrc/benchmarks/micro/property-benchmarks.js")) { | ||
cx.evaluateReader(scope, rdr, "property-benchmarks.js", 1, null); | ||
} | ||
create = (Function) ScriptableObject.getProperty(scope, "createObject"); | ||
createFieldByField = | ||
(Function) ScriptableObject.getProperty(scope, "createObjectFieldByField"); | ||
getName = (Function) ScriptableObject.getProperty(scope, "getName"); | ||
check = (Function) ScriptableObject.getProperty(scope, "check"); | ||
|
||
object = create.call(cx, scope, null, new Object[] {"testing"}); | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void tearDown() { | ||
cx.close(); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public Object createObject(PropertyBenchmark.PropertyState state) { | ||
Object obj = state.create.call(state.cx, state.scope, null, new Object[] {"testing"}); | ||
String name = | ||
ScriptRuntime.toString( | ||
state.getName.call(state.cx, state.scope, null, new Object[] {obj})); | ||
if (!"testing".equals(name)) { | ||
throw new AssertionError("Expected testing"); | ||
} | ||
return name; | ||
} | ||
|
||
@Benchmark | ||
public Object createObjectFieldByField(PropertyBenchmark.PropertyState state) { | ||
Object obj = | ||
state.createFieldByField.call( | ||
state.cx, state.scope, null, new Object[] {"testing"}); | ||
String name = | ||
ScriptRuntime.toString( | ||
state.getName.call(state.cx, state.scope, null, new Object[] {obj})); | ||
if (!"testing".equals(name)) { | ||
throw new AssertionError("Expected testing"); | ||
} | ||
return name; | ||
} | ||
|
||
@Benchmark | ||
public Object getOneProperty(PropertyBenchmark.PropertyState state) { | ||
String name = | ||
ScriptRuntime.toString( | ||
state.getName.call( | ||
state.cx, state.scope, null, new Object[] {state.object})); | ||
if (!"testing".equals(name)) { | ||
throw new AssertionError("Expected testing"); | ||
} | ||
return name; | ||
} | ||
|
||
@Benchmark | ||
public Object addTwoProperties(PropertyBenchmark.PropertyState state) { | ||
return state.check.call(state.cx, state.scope, null, new Object[] {state.object}); | ||
} | ||
} |
Oops, something went wrong.