Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3a140ab2b30d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1a7a4823f6be
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 25, 2018

  1. Copy the full SHA
    f0450cb View commit details
  2. [bench] sample benchmark for RubyString implements CharSequence

    ```
    Benchmark                                        Mode  Cnt       Score      Error   Units
    StringLoopBenchmark.benchLongDecodeStringLoop   thrpt    5   10601.329 ±  530.061  ops/ms
    StringLoopBenchmark.benchLongJavaStringLoop     thrpt    5   10653.619 ±  786.823  ops/ms
    StringLoopBenchmark.benchLongRubyStringLoop     thrpt    5   20799.312 ± 1440.544  ops/ms
    StringLoopBenchmark.benchShortDecodeStringLoop  thrpt    5   16571.679 ±  566.696  ops/ms
    StringLoopBenchmark.benchShortJavaStringLoop    thrpt    5   16073.402 ± 1785.195  ops/ms
    StringLoopBenchmark.benchShortRubyStringLoop    thrpt    5  103646.077 ± 2765.196  ops/ms
    ```
    kares committed May 25, 2018
    Copy the full SHA
    1a7a482 View commit details
Showing with 97 additions and 10 deletions.
  1. +2 −2 bench/pom.rb
  2. +8 −8 bench/pom.xml
  3. +87 −0 bench/src/main/java/org/jruby/benchmark/StringLoopBenchmark.java
4 changes: 2 additions & 2 deletions bench/pom.rb
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@
'compilerArgs' => { 'arg' => '-J-Xmx1G' },
'showWarnings' => 'true',
'showDeprecation' => 'true',
'source' => ['${base.java.version}', '1.7'],
'target' => ['${base.javac.version}', '1.7'],
'source' => ['${base.java.version}', '1.8'],
'target' => ['${base.javac.version}', '1.8'],
'useIncrementalCompilation' => 'false')

plugin :shade do
16 changes: 8 additions & 8 deletions bench/pom.xml
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.2.0.0-SNAPSHOT</version>
<version>9.2.1.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-benchmark</artifactId>
<name>JRuby Benchmark</name>
<properties>
<version.ruby>2.4.1</version.ruby>
<version.ruby>2.5.0</version.ruby>
<prawn.dir>${test.dir}/prawn</prawn.dir>
<spec.tags.dir>${spec.dir}/tags</spec.tags.dir>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
@@ -26,8 +26,8 @@ DO NOT MODIFIY - GENERATED CODE
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
<installer.gems>${jruby.win32ole.gem}</installer.gems>
<prawn.git.repo>git://github.com/sandal/prawn.git</prawn.git.repo>
<version.ruby.minor>1</version.ruby.minor>
<install4j.executable>/Applications/install4j 4/bin/install4jc</install4j.executable>
<version.ruby.minor>0</version.ruby.minor>
<install4j.executable>/Applications/install4j7/bin/install4jc</install4j.executable>
<jay.bin>jay</jay.bin>
<polyglot.dump.readonly>true</polyglot.dump.readonly>
<dest.lib.dir>${lib.dir}</dest.lib.dir>
@@ -36,14 +36,14 @@ DO NOT MODIFIY - GENERATED CODE
<maven.test.skip>true</maven.test.skip>
<rubyspec.1.8.dir>${rubyspec.dir}/1.8</rubyspec.1.8.dir>
<jruby.launch.memory>1024M</jruby.launch.memory>
<version.ruby.major>2.4</version.ruby.major>
<version.ruby.major>2.5</version.ruby.major>
<release.dir>release</release.dir>
<lib.dir>lib</lib.dir>
<rails.dir>${test.dir}/rails</rails.dir>
<parser.dir>core/src/main/java/org/jruby/parser</parser.dir>
<jruby.basedir>${basedir}/..</jruby.basedir>
<rubyspec.dir>${spec.dir}/ruby</rubyspec.dir>
<version.ruby.revision>58053</version.ruby.revision>
<version.ruby.revision>60928</version.ruby.revision>
<mspec.dir>${spec.dir}/mspec</mspec.dir>
<build.date>${maven.build.timestamp}</build.date>
<main.basedir>${project.parent.basedir}</main.basedir>
@@ -97,9 +97,9 @@ DO NOT MODIFIY - GENERATED CODE
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<source>${base.java.version}</source>
<source>1.7</source>
<source>1.8</source>
<target>${base.javac.version}</target>
<target>1.7</target>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
87 changes: 87 additions & 0 deletions bench/src/main/java/org/jruby/benchmark/StringLoopBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.jruby.benchmark;

import java.util.concurrent.TimeUnit;

import org.jruby.Ruby;
import org.jruby.RubyString;
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 = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
public class StringLoopBenchmark {

private static final int INVOCATIONS = 1_000_000;

private static final Ruby RUBY = Ruby.newInstance();

private static final String SHORT_STR = "1234567890";
private static final RubyString SHORT = RubyString.newString(RUBY, SHORT_STR);

private static final String LONG_STR = "1234567890_abcdefghijklmnoprstuvxyz-ABCDEFGHIJKLMNOPQRSTUVXYZ";
private static final RubyString LONG = RubyString.newString(RUBY, LONG_STR);

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchShortRubyStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsRuby(SHORT_STR, SHORT, blackhole);
}

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchShortJavaStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsJava(SHORT_STR, SHORT.decodeString(), blackhole);
}

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchShortDecodeStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsDecode(SHORT_STR, SHORT, blackhole);
}

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchLongRubyStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsRuby(LONG_STR, LONG, blackhole);
}

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchLongJavaStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsJava(LONG_STR, LONG.decodeString(), blackhole);
}

@Benchmark
@OperationsPerInvocation(INVOCATIONS)
public void benchLongDecodeStringLoop(final Blackhole blackhole) {
for (int i = 0; i < INVOCATIONS; i++) equalsDecode(LONG_STR, LONG, blackhole);
}

private static void equalsRuby(final String STR, final RubyString str, final Blackhole blackhole) {
blackhole.consume( STR.contentEquals(str) );
}

private static void equalsJava(final String STR, final String str, final Blackhole blackhole) {
blackhole.consume( STR.contentEquals(str) );
}

private static void equalsDecode(final String STR, final RubyString str, final Blackhole blackhole) {
blackhole.consume( STR.contentEquals(str.decodeString()) );
}
}