-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported remaining Java benchmarks to JMH (#4774)
closes #4752
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
1 parent
b961a0e
commit 222fda5
Showing
4 changed files
with
201 additions
and
175 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
bench/src/main/java/org/jruby/benchmark/EventHookBenchmark.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,139 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyInstanceConfig; | ||
import org.jruby.runtime.Binding; | ||
import org.jruby.runtime.EventHook; | ||
import org.jruby.runtime.RubyEvent; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
@Warmup(iterations = 3, time = 3) | ||
@Measurement(iterations = 10, time = 3) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class EventHookBenchmark { | ||
|
||
private static final int INVOCATIONS = 10; | ||
|
||
private static final String BOOT_SCRIPT = | ||
"def fib(a) \n if a.send :<, \n 2 \n a \n else \n fib(a.send :-, 1).send :+, \n fib(a.send :-, 2) \n end \n end"; | ||
|
||
private static final String RUN_SCRIPT = "fib(30)"; | ||
|
||
private static final Ruby RUNTIME = initRuntime(); | ||
private static final Ruby INTERP_RUNTIME = initInterpRuntime(); | ||
private static final Ruby TRACED_RUNTIME = initTracedRuntime(); | ||
private static final Ruby HOOKED_RUNTIME_ONE = initHookedRuntime( | ||
new EventHook() { | ||
@Override | ||
public void eventHandler(final ThreadContext context, final String eventName, | ||
final String file, final int line, final String name, final IRubyObject type) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public boolean isInterestedInEvent(final RubyEvent event) { | ||
// want everything | ||
return true; | ||
} | ||
}); | ||
private static final Ruby HOOKED_RUNTIME_TWO = initHookedRuntime( | ||
new EventHook() { | ||
@Override | ||
public void eventHandler(final ThreadContext context, final String eventName, | ||
final String file, final int line, final String name, final IRubyObject type) { | ||
// get binding | ||
final Binding binding = context.currentBinding(); | ||
} | ||
|
||
@Override | ||
public boolean isInterestedInEvent(final RubyEvent event) { | ||
// want everything | ||
return true; | ||
} | ||
} | ||
); | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchControl() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchInterp() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
INTERP_RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchTraced() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
TRACED_RUNTIME.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchHooked1() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
HOOKED_RUNTIME_ONE.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchHooked2() { | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
HOOKED_RUNTIME_TWO.evalScriptlet(RUN_SCRIPT); | ||
} | ||
} | ||
|
||
private static Ruby initRuntime() { | ||
final RubyInstanceConfig config = new RubyInstanceConfig(); | ||
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF); | ||
config.setObjectSpaceEnabled(true); | ||
final Ruby runtime = Ruby.newInstance(config); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initInterpRuntime() { | ||
final Ruby runtime = Ruby.newInstance(new RubyInstanceConfig()); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initTracedRuntime() { | ||
final RubyInstanceConfig config = new RubyInstanceConfig(); | ||
RubyInstanceConfig.FULL_TRACE_ENABLED = true; | ||
final Ruby runtime = Ruby.newInstance(config); | ||
runtime.evalScriptlet(BOOT_SCRIPT); | ||
return runtime; | ||
} | ||
|
||
private static Ruby initHookedRuntime(final EventHook hook) { | ||
final Ruby runtime = initTracedRuntime(); | ||
runtime.addEventHook(hook); | ||
return runtime; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
bench/src/main/java/org/jruby/benchmark/FixnumCreationBenchmark.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,62 @@ | ||
package org.jruby.benchmark; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyFixnum; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 20, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Fork(1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Thread) | ||
public class FixnumCreationBenchmark { | ||
|
||
private static final int INVOCATIONS = 1_000_000; | ||
|
||
private static final Ruby RUBY = Ruby.newInstance(); | ||
|
||
private static final RubyFixnum ONE = RubyFixnum.newFixnum(RUBY, 1L); | ||
|
||
private static final RubyFixnum TWO = RubyFixnum.newFixnum(RUBY, 2L); | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(INVOCATIONS) | ||
public void benchFixnumCreation(final Blackhole blackhole) { | ||
final long time = System.currentTimeMillis(); | ||
final Ruby ruby = RUBY; | ||
for (int i = 0; i < INVOCATIONS; i++) { | ||
blackhole.consume(RubyFixnum.newFixnum(ruby, time)); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void benchStaticFib(final Blackhole blackhole) { | ||
final Ruby ruby = RUBY; | ||
final ThreadContext context = ruby.getCurrentContext(); | ||
blackhole.consume(fib(context, RubyFixnum.newFixnum(ruby, 30L))); | ||
} | ||
|
||
private static IRubyObject fib(final ThreadContext context, final IRubyObject object) { | ||
final RubyFixnum value = (RubyFixnum) object; | ||
if (value.op_lt(context, TWO).isTrue()) { | ||
return value; | ||
} | ||
return ((RubyFixnum) fib(context, value.op_minus(context, TWO))) | ||
.op_plus(context, fib(context, value.op_minus(context, ONE))); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
core/src/test/java/org/jruby/bench/BenchFixnumCreation.java
This file was deleted.
Oops, something went wrong.