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: 61f8da434ac2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 926506577704
Choose a head ref

Commits on Apr 30, 2015

  1. Copy the full SHA
    979debc View commit details

Commits on May 1, 2015

  1. Copy the full SHA
    21fa527 View commit details
  2. Copy the full SHA
    4152b9b View commit details
  3. Copy the full SHA
    adc95e0 View commit details
  4. Copy the full SHA
    58c6722 View commit details
  5. [Truffle] adopt interop api changes and support more features (e.g. n…

    …il?)
    Matthias Grimmer committed May 1, 2015
    Copy the full SHA
    3232315 View commit details
  6. [Truffle] minor interop fixes

    Matthias Grimmer committed May 1, 2015
    Copy the full SHA
    f7f8ad7 View commit details
  7. [Truffle] minor interop fixes 2

    Matthias Grimmer committed May 1, 2015
    Copy the full SHA
    0c41e96 View commit details
  8. Copy the full SHA
    ec1bf1f View commit details
  9. Copy the full SHA
    33fae76 View commit details
  10. [Truffle] ignore src_gen files

    Matthias Grimmer committed May 1, 2015
    Copy the full SHA
    db87331 View commit details
  11. [Truffle] merge fix

    Matthias Grimmer committed May 1, 2015
    Copy the full SHA
    14a344f View commit details

Commits on May 2, 2015

  1. Copy the full SHA
    dd5eb06 View commit details
  2. Copy the full SHA
    bcda96e View commit details
  3. [Truffle] add missing RubyMethodForeignAccessFactory

    Matthias Grimmer committed May 2, 2015
    Copy the full SHA
    5d8ce18 View commit details
  4. Copy the full SHA
    83327ee View commit details

Commits on May 3, 2015

  1. Copy the full SHA
    ff7d4fe View commit details
  2. Copy the full SHA
    2fb2788 View commit details

Commits on May 4, 2015

  1. Copy the full SHA
    fc94c95 View commit details
  2. Copy the full SHA
    4ab6c57 View commit details

Commits on May 7, 2015

  1. Copy the full SHA
    e87a864 View commit details
  2. Copy the full SHA
    d41a2b5 View commit details
  3. Copy the full SHA
    293435f View commit details
  4. Copy the full SHA
    251030d View commit details
  5. Copy the full SHA
    2ec8488 View commit details
  6. Copy the full SHA
    91f0407 View commit details

Commits on May 8, 2015

  1. Copy the full SHA
    bd54763 View commit details

Commits on May 9, 2015

  1. Merge branch 'master' into truffle-head

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
    chrisseaton committed May 9, 2015
    Copy the full SHA
    08193c6 View commit details
  2. Copy the full SHA
    01c49d7 View commit details
  3. Copy the full SHA
    5de0ab0 View commit details
  4. Copy the full SHA
    e78948f View commit details

Commits on May 10, 2015

  1. Merge branch 'master' into truffle-head

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/nodes/interop/InteropNode.java
    chrisseaton committed May 10, 2015
    Copy the full SHA
    2660d99 View commit details

Commits on May 12, 2015

  1. Copy the full SHA
    c0d2d92 View commit details
  2. Copy the full SHA
    424e351 View commit details

Commits on May 13, 2015

  1. Copy the full SHA
    0f5f903 View commit details
  2. Copy the full SHA
    bf4bacb View commit details

Commits on May 14, 2015

  1. Copy the full SHA
    b510646 View commit details
  2. Copy the full SHA
    c966b40 View commit details
  3. Copy the full SHA
    56ca99e View commit details
  4. Copy the full SHA
    2fe04df View commit details
  5. Copy the full SHA
    f60bfba View commit details

Commits on May 16, 2015

  1. Copy the full SHA
    4bd8d71 View commit details

Commits on May 17, 2015

  1. Copy the full SHA
    29efc12 View commit details

Commits on May 18, 2015

  1. Copy the full SHA
    3fb7694 View commit details
  2. Copy the full SHA
    4cdf4f9 View commit details

Commits on May 20, 2015

  1. Merge branch 'master' into truffle-head

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
    	truffle/src/main/java/org/jruby/truffle/nodes/dispatch/UnresolvedDispatchNode.java
    chrisseaton committed May 20, 2015
    Copy the full SHA
    c40d698 View commit details

Commits on May 24, 2015

  1. Copy the full SHA
    69d8085 View commit details

Commits on May 25, 2015

  1. Copy the full SHA
    bffa746 View commit details

Commits on May 26, 2015

  1. Copy the full SHA
    e57f7a4 View commit details
  2. Copy the full SHA
    48dcafc View commit details
Showing 6,453 changed files with 319,345 additions and 145,696 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@
*.versionsBackup
*.zip
*~
*.tokens
*.su
*.ll

.DS_Store
.debug.properties
@@ -21,6 +24,9 @@
build
build.properties
build_graph.png
mx*/*pyc
mx*/env
mxbuild
core/src/main/java/org/jruby/runtime/Constants.java
dependency-reduced-pom.xml
dev_null
@@ -43,11 +49,14 @@ lib/ruby/gems
lib/ruby/stdlib/*jopenssl*.jar
lib/ruby/stdlib/bcpkix-jdk15on-*.jar
lib/ruby/stdlib/bcprov-jdk15on-*.jar
lib/ruby/stdlib/did_you_mean*
lib/ruby/stdlib/gauntlet_rdoc.rb
lib/ruby/stdlib/jar*
lib/ruby/stdlib/jline
lib/ruby/stdlib/jopenssl*
lib/ruby/stdlib/krypt*
lib/ruby/stdlib/net-telnet.rb
lib/ruby/stdlib/net/telnet*
lib/ruby/stdlib/openssl*
lib/ruby/stdlib/org/
lib/ruby/stdlib/readline/*readline*.jar
@@ -70,6 +79,7 @@ test/prawn
test/rails
test/testapp/testapp
test/truffle/*.methods
test/truffle/integration/gem-testing
tool/nailgun/Makefile
tool/nailgun/config.log
tool/nailgun/config.status
@@ -78,6 +88,7 @@ reference.txt
rubyspec_temp
.polyglot.pom.rb
tool/truffle/jruby_truffle_runner/jruby+truffle_runner-*.gem
test/truffle/cexts/**/Makefile

# binaries
!bin/gem
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.11</version>
<version>0.1.15</version>
</extension>
</extensions>
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.1/apache-maven-3.3.1-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
76 changes: 51 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -2,15 +2,18 @@ language: java

sudo: false

#cache:
# directories:
# - $HOME/.m2
cache:
directories:
- $HOME/.m2

before_script:
before_install:
- export MAVEN_SKIP_RC=true
- export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=512m"
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=240M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=240M -XX:CompressedClassSpaceSize=240M"; fi
- export MAVEN_OPTS="-Xmx512M $MAVEN_OPTS"

before_script:
- unset GEM_PATH GEM_HOME IRBRC JRUBY_OPTS
- "export PATH=`pwd`/bin:$PATH"
- export PATH="`pwd`/bin:$PATH"
- echo $HOME

jdk:
@@ -22,29 +25,27 @@ os:

env:
global:
- JAVA_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
- JAVA_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xmn48M -Xmx512M"
- MALLOC_ARENA_MAX=2
matrix:
- PHASE='-Ptest'
- PHASE='-Prake -Dtask=test:jruby'
- PHASE='-Prake -Dtask=test:jruby:fullint'
- PHASE='-Prake -Dtask=test:jruby:jit'
- PHASE='-Prake -Dtask=test:mri'
- PHASE='-Prake -Dtask=test:mri:fullint'
- PHASE='-Prake -Dtask=test:mri:jit'
- PHASE='-Prake -Dtask=test:slow_suites'
- PHASE='-Prake -Dtask=test:tracing'
- PHASE='-Prake -Dtask=spec:ji'
- PHASE='-Prake -Dtask=spec:compiler'
- PHASE='-Prake -Dtask=spec:compiler' JRUBY_OPTS=-Xcompile.invokedynamic
- PHASE='-Prake -Dtask=spec:ffi'
- PHASE='-Prake -Dtask=spec:regression'
- PHASE='-Prake -Dtask=spec:ruby:fast'
- PHASE='-Prake -Dtask=spec:jruby'
- PHASE='-Prake -Dtask=spec:jrubyc'
- PHASE='-Prake -Dtask=spec:profiler'
- PHASE='-Ptruffle-specs-language'
- PHASE='-Ptruffle-specs-core'
- PHASE='-Ptruffle-specs-library'
- PHASE='-Ptruffle-specs-truffle'
- PHASE='-Ptruffle-mri-tests'

matrix:
include:
@@ -70,11 +71,41 @@ matrix:
jdk: oraclejdk8
- env: COMMAND=test/check_versions.sh
jdk: oraclejdk8
- env: COMMAND=tool/truffle-findbugs.sh
# JRuby+Truffle needs Java 8
- env: JT='test specs :command_line'
jdk: oraclejdk8
- env: JT='test specs :language'
jdk: oraclejdk8
- env: JT='test specs :core'
jdk: oraclejdk8
- env: JT='test specs :library'
jdk: oraclejdk8
- env: JT='test specs :truffle'
jdk: oraclejdk8
- env: COMMAND='ruby tool/jt.rb check_ambiguous_arguments'
- env: JT='test integration'
jdk: oraclejdk8
- env: COMMAND=test/truffle/integration-tests.sh
- env:
- COMMAND=test/truffle/gems/install-gems.sh
- JT='test gems'
jdk: oraclejdk8
- env:
- JAVA_OPTS="$JAVA_OPTS -Xmx512m"
- HAS_REDIS=true
- JT='test ecosystem'
jdk: oraclejdk8
- env: JT='test tck'
jdk: oraclejdk8
- env:
- JT=check_ambiguous_arguments
- SKIP_BUILD=true
jdk: oraclejdk8
- env:
- USE_BUILD_PACK=yes
- JT='test fast'
jdk: oraclejdk8
allow_failures:
- env: PHASE='-Prake -Dtask=test:mri:fullint'
- env: JT='test mri'
jdk: oraclejdk8
# NOTE: build seems to never start (waited for any to finish for more than a day) - probably a travis-ci bug
#- env: PHASE='-Pmain'
@@ -83,16 +114,8 @@ matrix:
# group: edge
# jdk: oraclejdk9

branches:
only:
- master
- jruby-1_7
- truffle-head
- /^test-.*$/
- /^ha-feature/

script: if [[ -v COMMAND ]]; then $COMMAND; else ./mvnw install -Dinvoker.skip=false $PHASE | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]; fi
install: travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip -Dmaven.test.skip
install: tool/travis-install.sh
script: tool/travis-script.sh

notifications:
irc:
@@ -111,3 +134,6 @@ notifications:
# we are on a branch
on_success: always
on_failure: never

services:
- redis-server
4 changes: 2 additions & 2 deletions COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JRuby is Copyright (c) 2007-2015 The JRuby project, and is released
JRuby is Copyright (c) 2007-2016 The JRuby project, and is released
under a tri EPL/GPL/LGPL license. You can use it, redistribute it
and/or modify it under the terms of the:

@@ -12,7 +12,7 @@ bytelist (http://github.com/jruby/bytelist),
yydebug (http://svn.codehaus.org/jruby/trunk/jay/yydebug)
are released under the same copyright/license.

The Truffle component is copyright (c) 2013-2015 Oracle and/or its
The Truffle component is copyright (c) 2013-2016 Oracle and/or its
affiliates and is released under the same licenses.

Some additional libraries distributed with JRuby are not covered by
20 changes: 20 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Environment

Provide at least:
* JRuby version (`jruby -v`) and command line (flags, JRUBY_OPTS, etc)
* Operating system and platform (e.g. `uname -a`)

Other relevant info you may wish to add:
* Installed or activated gems
* Application/framework version (e.g. Rails, Sinatra)
* Environment variables

### Expected Behavior

* Describe your expectation of how JRuby should behave, perhaps by showing how CRuby/MRI behaves.
* Provide an executable Ruby script or a link to an example repository.

### Actual Behavior

* Describe or show the actual behavior.
* Provide text or screen capture showing the behavior.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ It aims to be a complete, correct and fast implementation of Ruby, at the same
time as providing powerful new features such as concurrency without a
[global-interpreter-lock](http://en.wikipedia.org/wiki/Global_Interpreter_Lock),
true parallelism, and tight integration to the Java language to allow you to
uses Java classes in your Ruby program and to allow JRuby to be embedded into a
use Java classes in your Ruby program and to allow JRuby to be embedded into a
Java application.

You can use JRuby simply as a faster version of Ruby, you can use it to run Ruby
@@ -40,7 +40,7 @@ For [`rbenv`](https://github.com/sstephenson/rbenv) you will need the
package manager can provide these. Then you can run:

```
$ rbenv install jruby-9.0.0.0-dev
$ rbenv install jruby-9.0.5.0
```

For [`rvm`](https://rvm.io) you can simply do:
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.5.0-SNAPSHOT
9.1.3.0-SNAPSHOT
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ build: off

environment:
matrix:
- JAVA_HOME: C:\Program Files\Java\jdk1.7.0
- JAVA_HOME: C:\Program Files (x86)\Java\jdk1.7.0
- JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0

File renamed without changes.
291 changes: 291 additions & 0 deletions bench/mri/bm_app_aobench.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
# AO render benchmark
# Original program (C) Syoyo Fujita in Javascript (and other languages)
# https://code.google.com/p/aobench/
# Ruby(yarv2llvm) version by Hideki Miura
#

IMAGE_WIDTH = 256
IMAGE_HEIGHT = 256
NSUBSAMPLES = 2
NAO_SAMPLES = 8

class Vec
def initialize(x, y, z)
@x = x
@y = y
@z = z
end

attr_accessor :x, :y, :z

def vadd(b)
Vec.new(@x + b.x, @y + b.y, @z + b.z)
end

def vsub(b)
Vec.new(@x - b.x, @y - b.y, @z - b.z)
end

def vcross(b)
Vec.new(@y * b.z - @z * b.y,
@z * b.x - @x * b.z,
@x * b.y - @y * b.x)
end

def vdot(b)
@x * b.x + @y * b.y + @z * b.z
end

def vlength
Math.sqrt(@x * @x + @y * @y + @z * @z)
end

def vnormalize
len = vlength
v = Vec.new(@x, @y, @z)
if len > 1.0e-17 then
v.x = v.x / len
v.y = v.y / len
v.z = v.z / len
end
v
end
end


class Sphere
def initialize(center, radius)
@center = center
@radius = radius
end

attr_reader :center, :radius

def intersect(ray, isect)
rs = ray.org.vsub(@center)
b = rs.vdot(ray.dir)
c = rs.vdot(rs) - (@radius * @radius)
d = b * b - c
if d > 0.0 then
t = - b - Math.sqrt(d)

if t > 0.0 and t < isect.t then
isect.t = t
isect.hit = true
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
ray.org.y + ray.dir.y * t,
ray.org.z + ray.dir.z * t)
n = isect.pl.vsub(@center)
isect.n = n.vnormalize
else
0.0
end
end
nil
end
end

class Plane
def initialize(p, n)
@p = p
@n = n
end

def intersect(ray, isect)
d = -@p.vdot(@n)
v = ray.dir.vdot(@n)
v0 = v
if v < 0.0 then
v0 = -v
end
if v0 < 1.0e-17 then
return
end

t = -(ray.org.vdot(@n) + d) / v

if t > 0.0 and t < isect.t then
isect.hit = true
isect.t = t
isect.n = @n
isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
ray.org.y + t * ray.dir.y,
ray.org.z + t * ray.dir.z)
end
nil
end
end

class Ray
def initialize(org, dir)
@org = org
@dir = dir
end

attr_accessor :org, :dir
end

class Isect
def initialize
@t = 10000000.0
@hit = false
@pl = Vec.new(0.0, 0.0, 0.0)
@n = Vec.new(0.0, 0.0, 0.0)
end

attr_accessor :t, :hit, :pl, :n
end

def clamp(f)
i = f * 255.5
if i > 255.0 then
i = 255.0
end
if i < 0.0 then
i = 0.0
end
i.to_i
end

def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)

if n.x < 0.6 and n.x > -0.6 then
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then
basis[1].z = 1.0
else
basis[1].x = 1.0
end

basis[0] = basis[1].vcross(basis[2])
basis[0] = basis[0].vnormalize

basis[1] = basis[2].vcross(basis[0])
basis[1] = basis[1].vnormalize
end

class Scene
def initialize
@spheres = Array.new
@spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
@spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
@spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5)
@plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
end

def ambient_occlusion(isect)
basis = Array.new
otherBasis(basis, isect.n)

ntheta = NAO_SAMPLES
nphi = NAO_SAMPLES
eps = 0.0001
occlusion = 0.0

p0 = Vec.new(isect.pl.x + eps * isect.n.x,
isect.pl.y + eps * isect.n.y,
isect.pl.z + eps * isect.n.z)
nphi.times do |j|
ntheta.times do |i|
r = rand
phi = 2.0 * 3.14159265 * rand
x = Math.cos(phi) * Math.sqrt(1.0 - r)
y = Math.sin(phi) * Math.sqrt(1.0 - r)
z = Math.sqrt(r)

rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
rz = x * basis[0].z + y * basis[1].z + z * basis[2].z

raydir = Vec.new(rx, ry, rz)
ray = Ray.new(p0, raydir)

occisect = Isect.new
@spheres[0].intersect(ray, occisect)
@spheres[1].intersect(ray, occisect)
@spheres[2].intersect(ray, occisect)
@plane.intersect(ray, occisect)
if occisect.hit then
occlusion = occlusion + 1.0
else
0.0
end
end
end

occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)

Vec.new(occlusion, occlusion, occlusion)
end

def render(w, h, nsubsamples)
cnt = 0
nsf = nsubsamples.to_f
h.times do |y|
w.times do |x|
rad = Vec.new(0.0, 0.0, 0.0)

# Subsampling
nsubsamples.times do |v|
nsubsamples.times do |u|

cnt = cnt + 1
wf = w.to_f
hf = h.to_f
xf = x.to_f
yf = y.to_f
uf = u.to_f
vf = v.to_f

px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)

eye = Vec.new(px, py, -1.0).vnormalize

ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)

isect = Isect.new
@spheres[0].intersect(ray, isect)
@spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect)
if isect.hit then
col = ambient_occlusion(isect)
rad.x = rad.x + col.x
rad.y = rad.y + col.y
rad.z = rad.z + col.z
end
end
end

r = rad.x / (nsf * nsf)
g = rad.y / (nsf * nsf)
b = rad.z / (nsf * nsf)
printf("%c", clamp(r))
printf("%c", clamp(g))
printf("%c", clamp(b))
end
nil
end

nil
end
end

alias printf_orig printf
def printf *args
end

# File.open("ao.ppm", "w") do |fp|
printf("P6\n")
printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
# end

undef printf
alias printf printf_orig
52 changes: 26 additions & 26 deletions bench/yarv/bm_app_erb.rb → bench/mri/bm_app_erb.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#
# Create many HTML strings with ERB.
#

require 'erb'

data = DATA.read
max = 5_000
title = "hello world!"
content = "hello world!\n" * 10

max.times{
ERB.new(data).result(binding)
}

__END__

<html>
<head> <%= title %> </head>
<body>
<h1> <%= title %> </h1>
<p>
<%= content %>
</p>
</body>
</html>
#
# Create many HTML strings with ERB.
#

require 'erb'

data = DATA.read
max = 15_000
title = "hello world!"
content = "hello world!\n" * 10

max.times{
ERB.new(data).result(binding)
}

__END__

<html>
<head> <%= title %> </head>
<body>
<h1> <%= title %> </h1>
<p>
<%= content %>
</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -6,6 +6,6 @@ def fact(n)
end
end

8.times{
100.times {
fact(5000)
}
}
File renamed without changes.
52 changes: 52 additions & 0 deletions bench/mri/bm_app_lc_fizzbuzz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# FizzBuzz program using only lambda calculus
#
# This program is quoted from
# "Understanding Computation" by Tom Stuart
# http://computationbook.com/
#
# You can understand why this program works fine by reading this book.
#

solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }]

FIRST = -> l { LEFT[RIGHT[l]] }
IF = -> b { b }
LEFT = -> p { p[-> x { -> y { x } } ] }
RIGHT = -> p { p[-> x { -> y { y } } ] }
IS_EMPTY = LEFT
REST = -> l { RIGHT[RIGHT[l]] }

def to_integer(proc)
proc[-> n { n + 1 }][0]
end

def to_boolean(proc)
IF[proc][true][false]
end

def to_array(proc)
array = []

until to_boolean(IS_EMPTY[proc])
array.push(FIRST[proc])
proc = REST[proc]
end

array
end

def to_char(c)
'0123456789BFiuz'.slice(to_integer(c))
end

def to_string(s)
to_array(s).map { |c| to_char(c) }.join
end

answer = to_array(solution).map do |p|
to_string(p)
end

answer_ary = answer.to_a
# puts answer_ary
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
def mandelbrot? z
i = 0
while i<100
i+=1
i += 1
z = z * z
return false if z.abs > 2
end
@@ -12,8 +12,8 @@ def mandelbrot? z

ary = []

(0..100).each{|dx|
(0..100).each{|dy|
(0..1000).each{|dx|
(0..1000).each{|dy|
x = dx / 50.0
y = dy / 50.0
c = Complex(x, y)
File renamed without changes.
4 changes: 2 additions & 2 deletions bench/yarv/bm_app_raise.rb → bench/mri/bm_app_raise.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i=0
i = 0
while i<300000
i+=1
i += 1
begin
raise
rescue
5 changes: 5 additions & 0 deletions bench/mri/bm_app_strconcat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
i = 0
while i<2_000_000
"#{1+1} #{1+1} #{1+1}"
i += 1
end
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions bench/yarv/bm_app_uri.rb → bench/mri/bm_app_uri.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'uri'

100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
require 'uri'

100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
14 changes: 14 additions & 0 deletions bench/mri/bm_array_shift.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'benchmark'

Benchmark.bm do |x|
[10_000,1_000_000,100_000_000].each do |n|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift"){ ary.shift }
(0..4).each do |i|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift(#{i})"){ ary.shift(i) }
end
end
end
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_aref_dsym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}
syms = ('a'..'z').map { |s| s.to_sym }
syms.each { |s| h[s] = 1 }
200_000.times { syms.each { |s| h[s] } }
21 changes: 21 additions & 0 deletions bench/mri/bm_hash_aref_dsym_long.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [ruby-core:70129] [Bug #11396]
collection_size = 200000
sample_size = 10000

values = (1..collection_size).to_a.map do |x|
"THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}"
end

symbol_hash = {}

values.each do |x|
symbol_hash[x.to_sym] = 1
end

# use the same samples each time to minimize deviations
rng = Random.new(0)
symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym)

3000.times do
symbol_sample_array.each { |x| symbol_hash[x] }
end
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_aref_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}
nums = (1..26).to_a
nums.each { |i| h[i] = i }
200_000.times { nums.each { |s| h[s] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_aref_flo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}
strs = [*1..10000].map! {|i| i.fdiv(10)}
strs.each { |s| h[s] = s }
50.times { strs.each { |s| h[s] } }
5 changes: 5 additions & 0 deletions bench/mri/bm_hash_aref_miss.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h = {}
strs = ('a'..'z').to_a.map!(&:freeze)
strs.each { |s| h[s] = s }
strs = ('A'..'Z').to_a
200_000.times { strs.each { |s| h[s] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_aref_str.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}
strs = ('a'..'z').to_a.map!(&:freeze)
strs.each { |s| h[s] = s }
200_000.times { strs.each { |s| h[s] } }
9 changes: 9 additions & 0 deletions bench/mri/bm_hash_aref_sym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h = {}
syms = ('a'..'z').to_a
begin
syms = eval("%i[#{syms.join(' ')}]")
rescue SyntaxError # <= 1.9.3
syms.map!(&:to_sym)
end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
13 changes: 13 additions & 0 deletions bench/mri/bm_hash_aref_sym_long.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
h = {}
syms = %w[puts warn syswrite write stat bacon lettuce tomato
some symbols in this array may already be interned others should not be
hash browns make good breakfast but not cooked using prime numbers
shift for division entries delete_if keys exist?
]
begin
syms = eval("%i[#{syms.join(' ')}]")
rescue SyntaxError # <= 1.9.3
syms.map!(&:to_sym)
end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
9 changes: 9 additions & 0 deletions bench/mri/bm_hash_flatten.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h = {}

10000.times do |i|
h[i] = nil
end

1000.times do
h.flatten
end
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_ident_flo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}.compare_by_identity
strs = (1..10000).to_a.map!(&:to_f)
strs.each { |s| h[s] = s }
50.times { strs.each { |s| h[s] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_ident_num.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}.compare_by_identity
nums = (1..26).to_a
nums.each { |n| h[n] = n }
200_000.times { nums.each { |n| h[n] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_ident_obj.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}.compare_by_identity
objs = 26.times.map { Object.new }
objs.each { |o| h[o] = o }
200_000.times { objs.each { |o| h[o] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_ident_str.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}.compare_by_identity
strs = ('a'..'z').to_a
strs.each { |s| h[s] = s }
200_000.times { strs.each { |s| h[s] } }
4 changes: 4 additions & 0 deletions bench/mri/bm_hash_ident_sym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h = {}.compare_by_identity
syms = ('a'..'z').to_a.map(&:to_sym)
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
9 changes: 9 additions & 0 deletions bench/mri/bm_hash_keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h = {}

10000.times do |i|
h[i] = nil
end

5000.times do
h.keys
end
10 changes: 10 additions & 0 deletions bench/mri/bm_hash_shift.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h = {}

10000.times do |i|
h[i] = nil
end

50000.times do
k, v = h.shift
h[k] = v
end
10 changes: 10 additions & 0 deletions bench/mri/bm_hash_shift_u16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h = {}

(16384..65536).each do |i|
h[i] = nil
end

300000.times do
k, v = h.shift
h[k] = v
end
10 changes: 10 additions & 0 deletions bench/mri/bm_hash_shift_u24.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h = {}

(0xff4000..0xffffff).each do |i|
h[i] = nil
end

300000.times do
k, v = h.shift
h[k] = v
end
10 changes: 10 additions & 0 deletions bench/mri/bm_hash_shift_u32.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h = {}

(0xffff4000..0xffffffff).each do |i|
h[i] = nil
end

300000.times do
k, v = h.shift
h[k] = v
end
9 changes: 9 additions & 0 deletions bench/mri/bm_hash_to_proc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h = {}

10000.times do |i|
h[i] = nil
end

5000.times do |i|
[i].map(&h)
end
9 changes: 9 additions & 0 deletions bench/mri/bm_hash_values.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h = {}

10000.times do |i|
h[i] = nil
end

5000.times do
h.values
end
26 changes: 13 additions & 13 deletions bench/yarv/bm_io_file_create.rb → bench/mri/bm_io_file_create.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# Create files
#

max = 50_000
file = './tmpfile_of_bm_io_file_create'

max.times{
f = open(file, 'w')
f.close#(true)
}
File.unlink(file)
#
# Create files
#

max = 200_000
file = './tmpfile_of_bm_io_file_create'

max.times{
f = open(file, 'w')
f.close#(true)
}
File.unlink(file)

30 changes: 15 additions & 15 deletions bench/yarv/bm_io_file_read.rb → bench/mri/bm_io_file_read.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#
# Seek and Read file.
#

require 'tempfile'

max = 20_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
f.write str

max.times{
f.seek 0
f.read
}
#
# Seek and Read file.
#

require 'tempfile'

max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
f.write str

max.times{
f.seek 0
f.read
}
28 changes: 14 additions & 14 deletions bench/yarv/bm_io_file_write.rb → bench/mri/bm_io_file_write.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# Seek and Write file.
#

require 'tempfile'

max = 20_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')

max.times{
f.seek 0
f.write str
}
#
# Seek and Write file.
#

require 'tempfile'

max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')

max.times{
f.seek 0
f.write str
}
22 changes: 22 additions & 0 deletions bench/mri/bm_io_nonblock_noex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
nr = 1_000_000
i = 0
msg = '.'
buf = '.'
noex = { exception: false }
begin
r, w = IO.pipe
while i < nr
i += 1
w.write_nonblock(msg, noex)
r.read_nonblock(1, buf, noex)
end
rescue ArgumentError # old Rubies
while i < nr
i += 1
w.write_nonblock(msg)
r.read_nonblock(1, buf)
end
ensure
r.close
w.close
end
21 changes: 21 additions & 0 deletions bench/mri/bm_io_nonblock_noex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
nr = 1_000_000
i = 0
msg = '.'
buf = '.'
begin
r, w = IO.pipe
while i < nr
i += 1
w.write_nonblock(msg, exception: false)
r.read_nonblock(1, buf, exception: false)
end
rescue ArgumentError # old Rubies
while i < nr
i += 1
w.write_nonblock(msg)
r.read_nonblock(1, buf)
end
ensure
r.close
w.close
end
9 changes: 9 additions & 0 deletions bench/mri/bm_io_select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IO.select performance

w = [ IO.pipe[1] ];

nr = 1000000
nr.times {
IO.select nil, w
}

22 changes: 22 additions & 0 deletions bench/mri/bm_io_select2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# IO.select performance. worst case of single fd.

ios = []
nr = 1000000
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"

((max / 2) - 10).times do
ios.concat IO.pipe
end

last = [ ios[-1] ]
puts "last IO: #{last[0].inspect}"

nr.times do
IO.select nil, last
end

21 changes: 21 additions & 0 deletions bench/mri/bm_io_select3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# IO.select performance. a lot of fd

ios = []
nr = 100
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"

(max - 10).times do
r, w = IO.pipe
r.close
ios.push w
end

nr.times do
IO.select nil, ios
end

3 changes: 3 additions & 0 deletions bench/mri/bm_loop_for.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for i in 1..30_000_000
#
end
File renamed without changes.
1 change: 1 addition & 0 deletions bench/mri/bm_loop_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
30_000_000.times{|e|}
4 changes: 4 additions & 0 deletions bench/mri/bm_loop_whileloop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
end
4 changes: 4 additions & 0 deletions bench/mri/bm_loop_whileloop2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i = 0
while i< 6_000_000 # benchmark loop 2
i += 1
end
2 changes: 2 additions & 0 deletions bench/mri/bm_marshal_dump_flo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bug10761 = 10000.times.map { |x| x.to_f }
100.times { Marshal.dump(bug10761) }
10 changes: 10 additions & 0 deletions bench/mri/bm_marshal_dump_load_geniv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a = ''
a.instance_eval do
@a = :a
@b = :b
@c = :c
end
100000.times do
a = Marshal.load(Marshal.dump(a))
end
#p(a.instance_eval { @a == :a && @b == :b && @c == :c })
1 change: 1 addition & 0 deletions bench/mri/bm_marshal_dump_load_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100000.times { Marshal.load(Marshal.dump(Time.now)) }
7 changes: 7 additions & 0 deletions bench/mri/bm_require.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$:.push File.join(File.dirname(__FILE__), "bm_require.data")

1.upto(10000) do |i|
require "c#{i}"
end

$:.pop
15 changes: 15 additions & 0 deletions bench/mri/bm_require_thread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$:.push File.join(File.dirname(__FILE__), "bm_require.data")

i=0
t = Thread.new do
while true
i = i+1 # dummy loop
end
end

1.upto(100) do |i|
require "c#{i}"
end

$:.pop
t.kill
5 changes: 5 additions & 0 deletions bench/mri/bm_securerandom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "securerandom"

20_0000.times do
SecureRandom.random_number(100)
end
File renamed without changes.
File renamed without changes.
119 changes: 62 additions & 57 deletions bench/yarv/bm_so_binary_trees.rb → bench/mri/bm_so_binary_trees.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
# The Computer Language Shootout Benchmarks
# http://shootout.alioth.debian.org
#
# contributed by Jesse Millikan

# disable output
def STDOUT.write_ *args
end

def item_check(tree)
if tree[0] == nil
tree[1]
else
tree[1] + item_check(tree[0]) - item_check(tree[2])
end
end

def bottom_up_tree(item, depth)
if depth > 0
item_item = 2 * item
depth -= 1
[bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
else
[nil, item, nil]
end
end

max_depth = 12 # 16 # ARGV[0].to_i
min_depth = 4

max_depth = min_depth + 2 if min_depth + 2 > max_depth

stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)

puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil

long_lived_tree = bottom_up_tree(0, max_depth)

min_depth.step(max_depth + 1, 2) do |depth|
iterations = 2**(max_depth - depth + min_depth)

check = 0

for i in 1..iterations
temp_tree = bottom_up_tree(i, depth)
check += item_check(temp_tree)

temp_tree = bottom_up_tree(-i, depth)
check += item_check(temp_tree)
end

puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
end

puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"
# The Computer Language Shootout Benchmarks
# http://shootout.alioth.debian.org
#
# contributed by Jesse Millikan

# disable output
alias puts_orig puts
def puts str
# disable puts
end

def item_check(tree)
if tree[0] == nil
tree[1]
else
tree[1] + item_check(tree[0]) - item_check(tree[2])
end
end

def bottom_up_tree(item, depth)
if depth > 0
item_item = 2 * item
depth -= 1
[bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
else
[nil, item, nil]
end
end

max_depth = 16 # ARGV[0].to_i
min_depth = 4

max_depth = min_depth + 2 if min_depth + 2 > max_depth

stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)

puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil

long_lived_tree = bottom_up_tree(0, max_depth)

min_depth.step(max_depth + 1, 2) do |depth|
iterations = 2**(max_depth - depth + min_depth)

check = 0

for i in 1..iterations
temp_tree = bottom_up_tree(i, depth)
check += item_check(temp_tree)

temp_tree = bottom_up_tree(-i, depth)
check += item_check(temp_tree)
end

puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
end

puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"

undef puts
alias puts puts_orig
Original file line number Diff line number Diff line change
@@ -5,11 +5,11 @@
# based on code from Aristarkh A Zagorodnikov and Dat Nguyen

STUFF = "hello\n"
i=0
i = 0
while i<10
i+=1
i += 1
hello = ''
400000.times do |e|
4_000_000.times do |e|
hello << STUFF
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -56,6 +56,6 @@ def blowup(num)
i = 1
max = NUM+1
while i < max
i+=1
i += 1
some_function(i+1)
end
90 changes: 45 additions & 45 deletions bench/yarv/bm_so_fannkuch.rb → bench/mri/bm_so_fannkuch.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
# Modified by Ryan Williams
def fannkuch(n)
maxFlips, m, r, check = 0, n-1, n, 0
count = (1..n).to_a
perm = (1..n).to_a
while true
if check < 30
puts "#{perm}"
check += 1
end
while r != 1
count[r-1] = r
r -= 1
end
if perm[0] != 1 and perm[m] != n
perml = perm.clone #.dup
flips = 0
while (k = perml.first ) != 1
perml = perml.slice!(0, k).reverse + perml
flips += 1
end
maxFlips = flips if flips > maxFlips
end
while true
if r==n then return maxFlips end
perm.insert r,perm.shift
break if (count[r] -= 1) > 0
r += 1
end
end
end
def puts *args
end
N = 10 # (ARGV[0] || 1).to_i
puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
# Modified by Ryan Williams

def fannkuch(n)
maxFlips, m, r, check = 0, n-1, n, 0
count = (1..n).to_a
perm = (1..n).to_a

while true
if check < 30
puts "#{perm}"
check += 1
end

while r != 1
count[r-1] = r
r -= 1
end

if perm[0] != 1 and perm[m] != n
perml = perm.clone #.dup
flips = 0
while (k = perml.first ) != 1
perml = perml.slice!(0, k).reverse + perml
flips += 1
end
maxFlips = flips if flips > maxFlips
end
while true
if r==n then return maxFlips end
perm.insert r,perm.shift
break if (count[r] -= 1) > 0
r += 1
end
end
end

def puts *args
end

N = 9 # (ARGV[0] || 1).to_i
puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"

162 changes: 81 additions & 81 deletions bench/yarv/bm_so_fasta.rb → bench/mri/bm_so_fasta.rb
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
$last = 42.0
def gen_random (max,im=139968,ia=3877,ic=29573)
(max * ($last = ($last * ia + ic) % im)) / im
end
alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
iub = [
["a", 0.27],
["c", 0.12],
["g", 0.12],
["t", 0.27],
["B", 0.02],
["D", 0.02],
["H", 0.02],
["K", 0.02],
["M", 0.02],
["N", 0.02],
["R", 0.02],
["S", 0.02],
["V", 0.02],
["W", 0.02],
["Y", 0.02],
]
homosapiens = [
["a", 0.3029549426680],
["c", 0.1979883004921],
["g", 0.1975473066391],
["t", 0.3015094502008],
]
def make_repeat_fasta(id, desc, src, n)
puts ">#{id} #{desc}"
v = nil
width = 60
l = src.length
s = src * ((n / l) + 1)
s.slice!(n, l)
puts(s.scan(/.{1,#{width}}/).join("\n"))
end
def make_random_fasta(id, desc, table, n)
puts ">#{id} #{desc}"
rand, v = nil,nil
width = 60
chunk = 1 * width
prob = 0.0
table.each{|v| v[1]= (prob += v[1])}
for i in 1..(n/width)
puts((1..width).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
if n%width != 0
puts((1..(n%width)).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
end
n = (ARGV[0] or 250_000).to_i
make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura

$last = 42.0
def gen_random (max,im=139968,ia=3877,ic=29573)
(max * ($last = ($last * ia + ic) % im)) / im
end

alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"

iub = [
["a", 0.27],
["c", 0.12],
["g", 0.12],
["t", 0.27],

["B", 0.02],
["D", 0.02],
["H", 0.02],
["K", 0.02],
["M", 0.02],
["N", 0.02],
["R", 0.02],
["S", 0.02],
["V", 0.02],
["W", 0.02],
["Y", 0.02],
]
homosapiens = [
["a", 0.3029549426680],
["c", 0.1979883004921],
["g", 0.1975473066391],
["t", 0.3015094502008],
]

def make_repeat_fasta(id, desc, src, n)
puts ">#{id} #{desc}"
v = nil
width = 60
l = src.length
s = src * ((n / l) + 1)
s.slice!(n, l)
puts(s.scan(/.{1,#{width}}/).join("\n"))
end

def make_random_fasta(id, desc, table, n)
puts ">#{id} #{desc}"
rand, v = nil,nil
width = 60
chunk = 1 * width
prob = 0.0
table.each{|v| v[1]= (prob += v[1])}
for i in 1..(n/width)
puts((1..width).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
if n%width != 0
puts((1..(n%width)).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
end


n = (ARGV[0] or 250_000).to_i

make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)

Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# contributed by jose fco. gonzalez
# modified by Sokolov Yura
seq = String.new
def frecuency( seq,length )
n, table = seq.length - length + 1, Hash.new(0)
f, i = nil, nil
(0 ... length).each do |f|
(f ... n).step(length) do |i|
table[seq[i,length]] += 1
end
end
[n,table]
end
def sort_by_freq( seq,length )
n,table = frecuency( seq,length )
a, b, v = nil, nil, nil
table.sort{|a,b| b[1] <=> a[1]}.each do |v|
puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)]
end
puts
end
def find_seq( seq,s )
n,table = frecuency( seq,s.length )
puts "#{table[s].to_s}\t#{s.upcase}"
end
input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb')
line = input.gets while line !~ /^>THREE/
line = input.gets
while (line !~ /^>/) & line do
seq << line.chomp
line = input.gets
end
[1,2].each {|i| sort_by_freq( seq,i ) }
%w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) }
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# contributed by jose fco. gonzalez
# modified by Sokolov Yura

seq = String.new

def frecuency( seq,length )
n, table = seq.length - length + 1, Hash.new(0)
f, i = nil, nil
(0 ... length).each do |f|
(f ... n).step(length) do |i|
table[seq[i,length]] += 1
end
end
[n,table]

end

def sort_by_freq( seq,length )
n,table = frecuency( seq,length )
a, b, v = nil, nil, nil
table.sort{|a,b| b[1] <=> a[1]}.each do |v|
puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)]
end
puts
end

def find_seq( seq,s )
n,table = frecuency( seq,s.length )
puts "#{table[s].to_s}\t#{s.upcase}"
end

input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb')

line = input.gets while line !~ /^>THREE/
line = input.gets

while (line !~ /^>/) & line do
seq << line.chomp
line = input.gets
end

[1,2].each {|i| sort_by_freq( seq,i ) }

%w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) }

4 changes: 2 additions & 2 deletions bench/yarv/bm_so_lists.rb → bench/mri/bm_so_lists.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby

NUM = 100
NUM = 300
SIZE = 10000

def test_lists()
@@ -40,7 +40,7 @@ def test_lists()

i = 0
while i<NUM
i+=1
i += 1
result = test_lists()
end

114 changes: 57 additions & 57 deletions bench/yarv/bm_so_mandelbrot.rb → bench/mri/bm_so_mandelbrot.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
#
# contributed by Karl von Laudermann
# modified by Jeremy Echols
size = 600 # ARGV[0].to_i
puts "P4\n#{size} #{size}"
ITER = 49 # Iterations - 1 for easy for..in looping
LIMIT_SQUARED = 4.0 # Presquared limit
byte_acc = 0
bit_num = 0
count_size = size - 1 # Precomputed size for easy for..in looping
# For..in loops are faster than .upto, .downto, .times, etc.
for y in 0..count_size
for x in 0..count_size
zr = 0.0
zi = 0.0
cr = (2.0*x/size)-1.5
ci = (2.0*y/size)-1.0
escape = false
# To make use of the for..in code, we use a dummy variable,
# like one would in C
for dummy in 0..ITER
tr = zr*zr - zi*zi + cr
ti = 2*zr*zi + ci
zr, zi = tr, ti
if (zr*zr+zi*zi) > LIMIT_SQUARED
escape = true
break
end
end
byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
bit_num += 1
# Code is very similar for these cases, but using separate blocks
# ensures we skip the shifting when it's unnecessary, which is most cases.
if (bit_num == 8)
print byte_acc.chr
byte_acc = 0
bit_num = 0
elsif (x == count_size)
byte_acc <<= (8 - bit_num)
print byte_acc.chr
byte_acc = 0
bit_num = 0
end
end
end
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
#
# contributed by Karl von Laudermann
# modified by Jeremy Echols

size = 600 # ARGV[0].to_i

puts "P4\n#{size} #{size}"

ITER = 49 # Iterations - 1 for easy for..in looping
LIMIT_SQUARED = 4.0 # Presquared limit

byte_acc = 0
bit_num = 0

count_size = size - 1 # Precomputed size for easy for..in looping

# For..in loops are faster than .upto, .downto, .times, etc.
for y in 0..count_size
for x in 0..count_size
zr = 0.0
zi = 0.0
cr = (2.0*x/size)-1.5
ci = (2.0*y/size)-1.0
escape = false

# To make use of the for..in code, we use a dummy variable,
# like one would in C
for dummy in 0..ITER
tr = zr*zr - zi*zi + cr
ti = 2*zr*zi + ci
zr, zi = tr, ti

if (zr*zr+zi*zi) > LIMIT_SQUARED
escape = true
break
end
end

byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
bit_num += 1

# Code is very similar for these cases, but using separate blocks
# ensures we skip the shifting when it's unnecessary, which is most cases.
if (bit_num == 8)
print byte_acc.chr
byte_acc = 0
bit_num = 0
elsif (x == count_size)
byte_acc <<= (8 - bit_num)
print byte_acc.chr
byte_acc = 0
bit_num = 0
end
end
end
2 changes: 1 addition & 1 deletion bench/yarv/bm_so_matrix.rb → bench/mri/bm_so_matrix.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

n = 60 #Integer(ARGV.shift || 1)

size = 30
size = 40

def mkmatrix(rows, cols)
count = 1
1,127 changes: 563 additions & 564 deletions bench/yarv/bm_so_meteor_contest.rb → bench/mri/bm_so_meteor_contest.rb

Large diffs are not rendered by default.

296 changes: 148 additions & 148 deletions bench/yarv/bm_so_nbody.rb → bench/mri/bm_so_nbody.rb
Original file line number Diff line number Diff line change
@@ -1,148 +1,148 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# Optimized for Ruby by Jesse Millikan
# From version ported by Michael Neumann from the C gcc version,
# which was written by Christoph Bauer.
SOLAR_MASS = 4 * Math::PI**2
DAYS_PER_YEAR = 365.24
def _puts *args
end
class Planet
attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass
def initialize(x, y, z, vx, vy, vz, mass)
@x, @y, @z = x, y, z
@vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
@mass = mass * SOLAR_MASS
end
def move_from_i(bodies, nbodies, dt, i)
while i < nbodies
b2 = bodies[i]
dx = @x - b2.x
dy = @y - b2.y
dz = @z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
mag = dt / (distance * distance * distance)
b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag
@vx -= dx * b2_mass_mag
@vy -= dy * b2_mass_mag
@vz -= dz * b2_mass_mag
b2.vx += dx * b_mass_mag
b2.vy += dy * b_mass_mag
b2.vz += dz * b_mass_mag
i += 1
end
@x += dt * @vx
@y += dt * @vy
@z += dt * @vz
end
end
def energy(bodies)
e = 0.0
nbodies = bodies.size
for i in 0 ... nbodies
b = bodies[i]
e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
for j in (i + 1) ... nbodies
b2 = bodies[j]
dx = b.x - b2.x
dy = b.y - b2.y
dz = b.z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
e -= (b.mass * b2.mass) / distance
end
end
e
end
def offset_momentum(bodies)
px, py, pz = 0.0, 0.0, 0.0
for b in bodies
m = b.mass
px += b.vx * m
py += b.vy * m
pz += b.vz * m
end
b = bodies[0]
b.vx = - px / SOLAR_MASS
b.vy = - py / SOLAR_MASS
b.vz = - pz / SOLAR_MASS
end
BODIES = [
# sun
Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
# jupiter
Planet.new(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
1.66007664274403694e-03,
7.69901118419740425e-03,
-6.90460016972063023e-05,
9.54791938424326609e-04),
# saturn
Planet.new(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
-2.76742510726862411e-03,
4.99852801234917238e-03,
2.30417297573763929e-05,
2.85885980666130812e-04),
# uranus
Planet.new(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
2.96460137564761618e-03,
2.37847173959480950e-03,
-2.96589568540237556e-05,
4.36624404335156298e-05),
# neptune
Planet.new(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
2.68067772490389322e-03,
1.62824170038242295e-03,
-9.51592254519715870e-05,
5.15138902046611451e-05)
]
init = 200_000 # ARGV[0]
n = Integer(init)
offset_momentum(BODIES)
puts "%.9f" % energy(BODIES)
nbodies = BODIES.size
dt = 0.01
n.times do
i = 0
while i < nbodies
b = BODIES[i]
b.move_from_i(BODIES, nbodies, dt, i + 1)
i += 1
end
end
puts "%.9f" % energy(BODIES)
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# Optimized for Ruby by Jesse Millikan
# From version ported by Michael Neumann from the C gcc version,
# which was written by Christoph Bauer.

SOLAR_MASS = 4 * Math::PI**2
DAYS_PER_YEAR = 365.24

def _puts *args
end

class Planet
attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass

def initialize(x, y, z, vx, vy, vz, mass)
@x, @y, @z = x, y, z
@vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
@mass = mass * SOLAR_MASS
end

def move_from_i(bodies, nbodies, dt, i)
while i < nbodies
b2 = bodies[i]
dx = @x - b2.x
dy = @y - b2.y
dz = @z - b2.z

distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
mag = dt / (distance * distance * distance)
b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag

@vx -= dx * b2_mass_mag
@vy -= dy * b2_mass_mag
@vz -= dz * b2_mass_mag
b2.vx += dx * b_mass_mag
b2.vy += dy * b_mass_mag
b2.vz += dz * b_mass_mag
i += 1
end

@x += dt * @vx
@y += dt * @vy
@z += dt * @vz
end
end

def energy(bodies)
e = 0.0
nbodies = bodies.size

for i in 0 ... nbodies
b = bodies[i]
e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
for j in (i + 1) ... nbodies
b2 = bodies[j]
dx = b.x - b2.x
dy = b.y - b2.y
dz = b.z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
e -= (b.mass * b2.mass) / distance
end
end
e
end

def offset_momentum(bodies)
px, py, pz = 0.0, 0.0, 0.0

for b in bodies
m = b.mass
px += b.vx * m
py += b.vy * m
pz += b.vz * m
end

b = bodies[0]
b.vx = - px / SOLAR_MASS
b.vy = - py / SOLAR_MASS
b.vz = - pz / SOLAR_MASS
end

BODIES = [
# sun
Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),

# jupiter
Planet.new(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
1.66007664274403694e-03,
7.69901118419740425e-03,
-6.90460016972063023e-05,
9.54791938424326609e-04),

# saturn
Planet.new(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
-2.76742510726862411e-03,
4.99852801234917238e-03,
2.30417297573763929e-05,
2.85885980666130812e-04),

# uranus
Planet.new(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
2.96460137564761618e-03,
2.37847173959480950e-03,
-2.96589568540237556e-05,
4.36624404335156298e-05),

# neptune
Planet.new(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
2.68067772490389322e-03,
1.62824170038242295e-03,
-9.51592254519715870e-05,
5.15138902046611451e-05)
]

init = 200_000 # ARGV[0]
n = Integer(init)

offset_momentum(BODIES)

puts "%.9f" % energy(BODIES)

nbodies = BODIES.size
dt = 0.01

n.times do
i = 0
while i < nbodies
b = BODIES[i]
b.move_from_i(BODIES, nbodies, dt, i + 1)
i += 1
end
end

puts "%.9f" % energy(BODIES)
File renamed without changes.
70 changes: 35 additions & 35 deletions bench/yarv/bm_so_nsieve.rb → bench/mri/bm_so_nsieve.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Glenn Parker, March 2005
# modified by Evan Phoenix, Sept 2006
def sieve(m)
flags = Flags.dup[0,m]
count = 0
pmax = m - 1
p = 2
while p <= pmax
unless flags[p].zero?
count += 1
mult = p
while mult <= pmax
flags[mult] = 0
mult += p
end
end
p += 1
end
count
end
n = 9 # (ARGV[0] || 2).to_i
Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*")
n.downto(n-2) do |exponent|
break if exponent < 0
m = (1 << exponent) * 10_000
# m = (2 ** exponent) * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Glenn Parker, March 2005
# modified by Evan Phoenix, Sept 2006

def sieve(m)
flags = Flags.dup[0,m]
count = 0
pmax = m - 1
p = 2
while p <= pmax
unless flags[p].zero?
count += 1
mult = p
while mult <= pmax
flags[mult] = 0
mult += p
end
end
p += 1
end
count
end

n = 9 # (ARGV[0] || 2).to_i
Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*")

n.downto(n-2) do |exponent|
break if exponent < 0
m = (1 << exponent) * 10_000
# m = (2 ** exponent) * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end
85 changes: 43 additions & 42 deletions bench/yarv/bm_so_nsieve_bits.rb → bench/mri/bm_so_nsieve_bits.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
#!/usr/bin/ruby
#
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# nsieve-bits in Ruby
# Contributed by Glenn Parker, March 2005

CharExponent = 3
BitsPerChar = 1 << CharExponent
LowMask = BitsPerChar - 1

def sieve(m)
items = "\xFF" * ((m / BitsPerChar) + 1)
masks = ""
BitsPerChar.times do |b|
masks << (1 << b).chr
end

count = 0
pmax = m - 1
2.step(pmax, 1) do |p|
if items[p >> CharExponent][p & LowMask] == 1
count += 1
p.step(pmax, p) do |mult|
a = mult >> CharExponent
b = mult & LowMask
items[a] -= masks[b] if items[a][b] != 0
end
end
end
count
end

n = 9 # (ARGV[0] || 2).to_i
n.step(n - 2, -1) do |exponent|
break if exponent < 0
m = 2 ** exponent * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end

#!/usr/bin/ruby
#coding: us-ascii
#
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# nsieve-bits in Ruby
# Contributed by Glenn Parker, March 2005

CharExponent = 3
BitsPerChar = 1 << CharExponent
LowMask = BitsPerChar - 1

def sieve(m)
items = "\xFF" * ((m / BitsPerChar) + 1)
masks = ""
BitsPerChar.times do |b|
masks << (1 << b).chr
end

count = 0
pmax = m - 1
2.step(pmax, 1) do |p|
if items[p >> CharExponent][p & LowMask] == 1
count += 1
p.step(pmax, p) do |mult|
a = mult >> CharExponent
b = mult & LowMask
items[a] -= masks[b] if items[a][b] != 0
end
end
end
count
end

n = 9 # (ARGV[0] || 2).to_i
n.step(n - 2, -1) do |exponent|
break if exponent < 0
m = 2 ** exponent * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
n = 2_500_000 # (ARGV.shift || 1).to_i
alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0
1.upto(n) do |d|
d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)
s0 += (2.0 / 3.0) ** (d - 1.0)
s1 += 1.0 / Math.sqrt(d)
s2 += 1.0 / (d * (d + 1.0))
s3 += 1.0 / (d3 * ds * ds)
s4 += 1.0 / (d3 * dc * dc)
s5 += 1.0 / d
s6 += 1.0 / d2
s7 += alt / d
s8 += alt / (2.0 * d - 1.0)
alt = -alt
end
if false
printf("%.9f\t(2/3)^k\n", s0)
printf("%.9f\tk^-0.5\n", s1)
printf("%.9f\t1/k(k+1)\n", s2)
printf("%.9f\tFlint Hills\n", s3)
printf("%.9f\tCookson Hills\n", s4)
printf("%.9f\tHarmonic\n", s5)
printf("%.9f\tRiemann Zeta\n", s6)
printf("%.9f\tAlternating Harmonic\n", s7)
printf("%.9f\tGregory\n", s8)
end
n = 2_500_000 # (ARGV.shift || 1).to_i

alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0

1.upto(n) do |d|
d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)

s0 += (2.0 / 3.0) ** (d - 1.0)
s1 += 1.0 / Math.sqrt(d)
s2 += 1.0 / (d * (d + 1.0))
s3 += 1.0 / (d3 * ds * ds)
s4 += 1.0 / (d3 * dc * dc)
s5 += 1.0 / d
s6 += 1.0 / d2
s7 += alt / d
s8 += alt / (2.0 * d - 1.0)

alt = -alt
end

if false
printf("%.9f\t(2/3)^k\n", s0)
printf("%.9f\tk^-0.5\n", s1)
printf("%.9f\t1/k(k+1)\n", s2)
printf("%.9f\tFlint Hills\n", s3)
printf("%.9f\tCookson Hills\n", s4)
printf("%.9f\tHarmonic\n", s5)
printf("%.9f\tRiemann Zeta\n", s6)
printf("%.9f\tAlternating Harmonic\n", s7)
printf("%.9f\tGregory\n", s8)
end
184 changes: 92 additions & 92 deletions bench/yarv/bm_so_pidigits.rb → bench/mri/bm_so_pidigits.rb
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Gabriele Renzi
class PiDigitSpigot
def initialize()
@z = Transformation.new 1,0,0,1
@x = Transformation.new 0,0,0,0
@inverse = Transformation.new 0,0,0,0
end
def next!
@y = @z.extract(3)
if safe? @y
@z = produce(@y)
@y
else
@z = consume @x.next!()
next!()
end
end
def safe?(digit)
digit == @z.extract(4)
end
def produce(i)
@inverse.qrst(10,-10*i,0,1).compose(@z)
end
def consume(a)
@z.compose(a)
end
end
class Transformation
attr_reader :q, :r, :s, :t
def initialize (q, r, s, t)
@q,@r,@s,@t,@k = q,r,s,t,0
end
def next!()
@q = @k = @k + 1
@r = 4 * @k + 2
@s = 0
@t = 2 * @k + 1
self
end
def extract(j)
(@q * j + @r) / (@s * j + @t)
end
def compose(a)
self.class.new( @q * a.q,
@q * a.r + r * a.t,
@s * a.q + t * a.s,
@s * a.r + t * a.t
)
end
def qrst *args
initialize *args
self
end
end
WIDTH = 10
n = 2_500 # Integer(ARGV[0])
j = 0
digits = PiDigitSpigot.new
while n > 0
if n >= WIDTH
WIDTH.times {print digits.next!}
j += WIDTH
else
n.times {print digits.next!}
(WIDTH-n).times {print " "}
j += n
end
puts "\t:"+j.to_s
n -= WIDTH
end
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Gabriele Renzi

class PiDigitSpigot

def initialize()
@z = Transformation.new 1,0,0,1
@x = Transformation.new 0,0,0,0
@inverse = Transformation.new 0,0,0,0
end

def next!
@y = @z.extract(3)
if safe? @y
@z = produce(@y)
@y
else
@z = consume @x.next!()
next!()
end
end

def safe?(digit)
digit == @z.extract(4)
end

def produce(i)
@inverse.qrst(10,-10*i,0,1).compose(@z)
end

def consume(a)
@z.compose(a)
end
end


class Transformation
attr_reader :q, :r, :s, :t
def initialize (q, r, s, t)
@q,@r,@s,@t,@k = q,r,s,t,0
end

def next!()
@q = @k = @k + 1
@r = 4 * @k + 2
@s = 0
@t = 2 * @k + 1
self
end

def extract(j)
(@q * j + @r) / (@s * j + @t)
end

def compose(a)
self.class.new( @q * a.q,
@q * a.r + r * a.t,
@s * a.q + t * a.s,
@s * a.r + t * a.t
)
end

def qrst *args
initialize *args
self
end


end


WIDTH = 10
n = 2_500 # Integer(ARGV[0])
j = 0

digits = PiDigitSpigot.new

while n > 0
if n >= WIDTH
WIDTH.times {print digits.next!}
j += WIDTH
else
n.times {print digits.next!}
(WIDTH-n).times {print " "}
j += n
end
puts "\t:"+j.to_s
n -= WIDTH
end

6 changes: 3 additions & 3 deletions bench/yarv/bm_so_random.rb → bench/mri/bm_so_random.rb
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ def gen_random(max)
(max * ($last = ($last * IA + IC) % IM)) / IM
end

N = 1000000
N = 3_000_000

i=0
i = 0
while i<N
i+=1
i +=1
gen_random(100.0)
end
# "%.9f" % gen_random(100.0)
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#!/usr/bin/ruby
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# Contributed by Peter Bjarke Olsen
# Modified by Doug King
seq=Array.new
def revcomp(seq)
seq.reverse!.tr!('wsatugcyrkmbdhvnATUGCYRKMBDHVN','WSTAACGRYMKVHDBNTAACGRYMKVHDBN')
stringlen=seq.length
0.step(stringlen-1,60) {|x| print seq.slice(x,60) , "\n"}
end
input = open(File.join(File.dirname($0), 'fasta.output.2500000'), 'rb')
while input.gets
if $_ =~ />/
if seq.length != 0
revcomp(seq.join)
seq=Array.new
end
puts $_
else
$_.sub(/\n/,'')
seq.push $_
end
end
revcomp(seq.join)
#!/usr/bin/ruby
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# Contributed by Peter Bjarke Olsen
# Modified by Doug King

seq=Array.new

def revcomp(seq)
seq.reverse!.tr!('wsatugcyrkmbdhvnATUGCYRKMBDHVN','WSTAACGRYMKVHDBNTAACGRYMKVHDBN')
stringlen=seq.length
0.step(stringlen-1,60) {|x| print seq.slice(x,60) , "\n"}
end

input = open(File.join(File.dirname($0), 'fasta.output.2500000'), 'rb')

while input.gets
if $_ =~ />/
if seq.length != 0
revcomp(seq.join)
seq=Array.new
end
puts $_
else
$_.sub(/\n/,'')
seq.push $_
end
end
revcomp(seq.join)
6 changes: 3 additions & 3 deletions bench/yarv/bm_so_sieve.rb → bench/mri/bm_so_sieve.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
num = 40
num = 500
count = i = j = 0
flags0 = Array.new(8192,1)
k = 0
while k < num
k+=1
k += 1
count = 0
flags = flags0.dup
i = 2
while i<8192
i+=1
i += 1
if flags[i]
# remove all multiples of prime: i
j = i*i
100 changes: 50 additions & 50 deletions bench/yarv/bm_so_spectralnorm.rb → bench/mri/bm_so_spectralnorm.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
def eval_A(i,j)
return 1.0/((i+j)*(i+j+1)/2+i+1)
end
def eval_A_times_u(u)
v, i = nil, nil
(0..u.length-1).collect { |i|
v = 0
for j in 0..u.length-1
v += eval_A(i,j)*u[j]
end
v
}
end
def eval_At_times_u(u)
v, i = nil, nil
(0..u.length-1).collect{|i|
v = 0
for j in 0..u.length-1
v += eval_A(j,i)*u[j]
end
v
}
end
def eval_AtA_times_u(u)
return eval_At_times_u(eval_A_times_u(u))
end
n = 500 # ARGV[0].to_i
u=[1]*n
for i in 1..10
v=eval_AtA_times_u(u)
u=eval_AtA_times_u(v)
end
vBv=0
vv=0
for i in 0..n-1
vBv += u[i]*v[i]
vv += v[i]*v[i]
end
str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
# print str
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura

def eval_A(i,j)
return 1.0/((i+j)*(i+j+1)/2+i+1)
end

def eval_A_times_u(u)
v, i = nil, nil
(0..u.length-1).collect { |i|
v = 0
for j in 0..u.length-1
v += eval_A(i,j)*u[j]
end
v
}
end

def eval_At_times_u(u)
v, i = nil, nil
(0..u.length-1).collect{|i|
v = 0
for j in 0..u.length-1
v += eval_A(j,i)*u[j]
end
v
}
end

def eval_AtA_times_u(u)
return eval_At_times_u(eval_A_times_u(u))
end

n = 500 # ARGV[0].to_i

u=[1]*n
for i in 1..10
v=eval_AtA_times_u(u)
u=eval_AtA_times_u(v)
end
vBv=0
vv=0
for i in 0..n-1
vBv += u[i]*v[i]
vv += v[i]*v[i]
end

str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
# print str
File renamed without changes.
14 changes: 14 additions & 0 deletions bench/mri/bm_vm1_attr_ivar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class C
attr_reader :a, :b
def initialize
@a = nil
@b = nil
end
end
obj = C.new
i = 0
while i<30_000_000 # while loop 1
i += 1
j = obj.a
k = obj.b
end
14 changes: 14 additions & 0 deletions bench/mri/bm_vm1_attr_ivar_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class C
attr_accessor :a, :b
def initialize
@a = nil
@b = nil
end
end
obj = C.new
i = 0
while i<30_000_000 # while loop 1
i += 1
obj.a = 1
obj.b = 2
end
10 changes: 10 additions & 0 deletions bench/mri/bm_vm1_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def m
yield
end

i = 0
while i<30_000_000 # while loop 1
i += 1
m{
}
end
8 changes: 8 additions & 0 deletions bench/mri/bm_vm1_const.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Const = 1

i = 0
while i<30_000_000 # while loop 1
i += 1
j = Const
k = Const
end
11 changes: 11 additions & 0 deletions bench/mri/bm_vm1_ensure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
begin
begin
ensure
end
ensure
end
end

7 changes: 7 additions & 0 deletions bench/mri/bm_vm1_float_simple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
i = 0.0; f = 0.0
while i<30_000_000
i += 1
f += 0.1; f -= 0.1
f += 0.1; f -= 0.1
f += 0.1; f -= 0.1
end
10 changes: 10 additions & 0 deletions bench/mri/bm_vm1_gc_short_lived.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
27 changes: 27 additions & 0 deletions bench/mri/bm_vm1_gc_short_with_complex_long.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def nested_hash h, n
if n == 0
''
else
10.times{
h[Object.new] = nested_hash(h, n-1)
}
end
end

long_lived = Hash.new
nested_hash long_lived, 6

GC.start
GC.start

i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end

13 changes: 13 additions & 0 deletions bench/mri/bm_vm1_gc_short_with_long.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
long_lived = Array.new(1_000_000){|i| "#{i}"}
GC.start
GC.start
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
15 changes: 15 additions & 0 deletions bench/mri/bm_vm1_gc_short_with_symbol.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# make many symbols
50_000.times{|i| sym = "sym#{i}".to_sym}
GC.start
GC.start

i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
12 changes: 12 additions & 0 deletions bench/mri/bm_vm1_gc_wb_ary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
short_lived_ary = []

if RUBY_VERSION >= "2.2.0"
GC.start(full_mark: false, immediate_mark: true, lazy_sweep: false)
end

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
short_lived_ary[0] = short_lived # write barrier
i+=1
end
14 changes: 14 additions & 0 deletions bench/mri/bm_vm1_gc_wb_ary_promoted.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
long_lived = []

if RUBY_VERSION > "2.2.0"
3.times{ GC.start(full_mark: false, immediate_mark: true, lazy_sweep: false) }
elsif
GC.start
end

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
long_lived[0] = short_lived # write barrier
i+=1
end
15 changes: 15 additions & 0 deletions bench/mri/bm_vm1_gc_wb_obj.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C
attr_accessor :foo
end
short_lived_obj = C.new

if RUBY_VERSION >= "2.2.0"
GC.start(full_mark: false, immediate_mark: true, lazy_sweep: false)
end

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
short_lived_obj.foo = short_lived # write barrier
i+=1
end
17 changes: 17 additions & 0 deletions bench/mri/bm_vm1_gc_wb_obj_promoted.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class C
attr_accessor :foo
end
long_lived = C.new

if RUBY_VERSION >= "2.2.0"
3.times{ GC.start(full_mark: false, immediate_mark: true, lazy_sweep: false) }
elsif
GC.start
end

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
long_lived.foo = short_lived # write barrier
i+=1
end
8 changes: 8 additions & 0 deletions bench/mri/bm_vm1_ivar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@a = 1

i = 0
while i<30_000_000 # while loop 1
i += 1
j = @a
k = @a
end
12 changes: 6 additions & 6 deletions bench/yarv/bm_vm1_ivar_set.rb → bench/mri/bm_vm1_ivar_set.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i = 0
while i<30_000_000 # while loop 1
i+= 1
@a = 1
@b = 2
end
i = 0
while i<30_000_000 # while loop 1
i += 1
@a = 1
@b = 2
end
9 changes: 9 additions & 0 deletions bench/mri/bm_vm1_length.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a = 'abc'
b = [1, 2, 3]
i = 0
while i<30_000_000 # while loop 1
i += 1
a.length
b.length
end

18 changes: 18 additions & 0 deletions bench/mri/bm_vm1_lvar_init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def m v
unless v
# unreachable code
v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v10 =
v11 = v12 = v13 = v14 = v15 = v16 = v17 = v18 = v19 = v20 =
v21 = v22 = v23 = v24 = v25 = v26 = v27 = v28 = v29 = v30 =
v31 = v32 = v33 = v34 = v35 = v36 = v37 = v38 = v39 = v40 =
v41 = v42 = v43 = v44 = v45 = v46 = v47 = v48 = v49 = v50 = 1
end
end

i = 0

while i<30_000_000 # while loop 1
i += 1
m i
end

5 changes: 5 additions & 0 deletions bench/mri/bm_vm1_lvar_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
i = 0
while i<30_000_000 # while loop 1
i += 1
a = b = c = d = e = f = g = h = j = k = l = m = n = o = p = q = r = 1
end
8 changes: 8 additions & 0 deletions bench/mri/bm_vm1_neq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
i = 0
obj1 = Object.new
obj2 = Object.new

while i<30_000_000 # while loop 1
i += 1
obj1 != obj2
end
7 changes: 7 additions & 0 deletions bench/mri/bm_vm1_not.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
i = 0
obj = Object.new

while i<30_000_000 # while loop 1
i += 1
!obj
end
7 changes: 7 additions & 0 deletions bench/mri/bm_vm1_rescue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
i = 0
while i<30_000_000 # while loop 1
i += 1
begin
rescue
end
end
9 changes: 9 additions & 0 deletions bench/mri/bm_vm1_simplereturn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def m
return 1
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m
end

8 changes: 8 additions & 0 deletions bench/mri/bm_vm1_swap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a = 1
b = 2
i = 0
while i<30_000_000 # while loop 1
i += 1
a, b = b, a
end

10 changes: 10 additions & 0 deletions bench/mri/bm_vm1_yield.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def m
i = 0
while i<30_000_000 # while loop 1
i += 1
yield
end
end

m{}

5 changes: 5 additions & 0 deletions bench/mri/bm_vm2_array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
a = [1,2,3,4,5,6,7,8,9,10]
end
106 changes: 106 additions & 0 deletions bench/mri/bm_vm2_bigarray.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
a = [
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
]
end
5 changes: 5 additions & 0 deletions bench/mri/bm_vm2_bighash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
i = 0
while i<60_000 # benchmark loop 2
i += 1
a = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, 30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, 40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, 50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, 60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, 70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, 80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, 90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, 100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, 110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, 120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126, 127=>127, 128=>128, 129=>129, 130=>130, 131=>131, 132=>132, 133=>133, 134=>134, 135=>135, 136=>136, 137=>137, 138=>138, 139=>139, 140=>140, 141=>141, 142=>142, 143=>143, 144=>144, 145=>145, 146=>146, 147=>147, 148=>148, 149=>149, 150=>150, 151=>151, 152=>152, 153=>153, 154=>154, 155=>155, 156=>156, 157=>157, 158=>158, 159=>159, 160=>160, 161=>161, 162=>162, 163=>163, 164=>164, 165=>165, 166=>166, 167=>167, 168=>168, 169=>169, 170=>170, 171=>171, 172=>172, 173=>173, 174=>174, 175=>175, 176=>176, 177=>177, 178=>178, 179=>179, 180=>180, 181=>181, 182=>182, 183=>183, 184=>184, 185=>185, 186=>186, 187=>187, 188=>188, 189=>189, 190=>190, 191=>191, 192=>192, 193=>193, 194=>194, 195=>195, 196=>196, 197=>197, 198=>198, 199=>199, 200=>200, 201=>201, 202=>202, 203=>203, 204=>204, 205=>205, 206=>206, 207=>207, 208=>208, 209=>209, 210=>210, 211=>211, 212=>212, 213=>213, 214=>214, 215=>215, 216=>216, 217=>217, 218=>218, 219=>219, 220=>220, 221=>221, 222=>222, 223=>223, 224=>224, 225=>225, 226=>226, 227=>227, 228=>228, 229=>229, 230=>230, 231=>231, 232=>232, 233=>233, 234=>234, 235=>235, 236=>236, 237=>237, 238=>238, 239=>239, 240=>240, 241=>241, 242=>242, 243=>243, 244=>244, 245=>245, 246=>246, 247=>247, 248=>248, 249=>249, 250=>250, 251=>251, 252=>252, 253=>253, 254=>254, 255=>255, 256=>256, 257=>257, 258=>258, 259=>259, 260=>260, 261=>261, 262=>262, 263=>263, 264=>264, 265=>265, 266=>266, 267=>267, 268=>268, 269=>269, 270=>270, 271=>271, 272=>272, 273=>273, 274=>274, 275=>275, 276=>276, 277=>277, 278=>278, 279=>279, 280=>280, 281=>281, 282=>282, 283=>283, 284=>284, 285=>285, 286=>286, 287=>287, 288=>288, 289=>289, 290=>290, 291=>291, 292=>292, 293=>293, 294=>294, 295=>295, 296=>296, 297=>297, 298=>298, 299=>299, 300=>300, 301=>301, 302=>302, 303=>303, 304=>304, 305=>305, 306=>306, 307=>307, 308=>308, 309=>309, 310=>310, 311=>311, 312=>312, 313=>313, 314=>314, 315=>315, 316=>316, 317=>317, 318=>318, 319=>319, 320=>320, 321=>321, 322=>322, 323=>323, 324=>324, 325=>325, 326=>326, 327=>327, 328=>328, 329=>329, 330=>330, 331=>331, 332=>332, 333=>333, 334=>334, 335=>335, 336=>336, 337=>337, 338=>338, 339=>339, 340=>340, 341=>341, 342=>342, 343=>343, 344=>344, 345=>345, 346=>346, 347=>347, 348=>348, 349=>349, 350=>350, 351=>351, 352=>352, 353=>353, 354=>354, 355=>355, 356=>356, 357=>357, 358=>358, 359=>359, 360=>360, 361=>361, 362=>362, 363=>363, 364=>364, 365=>365, 366=>366, 367=>367, 368=>368, 369=>369, 370=>370, 371=>371, 372=>372, 373=>373, 374=>374, 375=>375, 376=>376, 377=>377, 378=>378, 379=>379, 380=>380, 381=>381, 382=>382, 383=>383, 384=>384, 385=>385, 386=>386, 387=>387, 388=>388, 389=>389, 390=>390, 391=>391, 392=>392, 393=>393, 394=>394, 395=>395, 396=>396, 397=>397, 398=>398, 399=>399, 400=>400, 401=>401, 402=>402, 403=>403, 404=>404, 405=>405, 406=>406, 407=>407, 408=>408, 409=>409, 410=>410, 411=>411, 412=>412, 413=>413, 414=>414, 415=>415, 416=>416, 417=>417, 418=>418, 419=>419, 420=>420, 421=>421, 422=>422, 423=>423, 424=>424, 425=>425, 426=>426, 427=>427, 428=>428, 429=>429, 430=>430, 431=>431, 432=>432, 433=>433, 434=>434, 435=>435, 436=>436, 437=>437, 438=>438, 439=>439, 440=>440, 441=>441, 442=>442, 443=>443, 444=>444, 445=>445, 446=>446, 447=>447, 448=>448, 449=>449, 450=>450, 451=>451, 452=>452, 453=>453, 454=>454, 455=>455, 456=>456, 457=>457, 458=>458, 459=>459, 460=>460, 461=>461, 462=>462, 463=>463, 464=>464, 465=>465, 466=>466, 467=>467, 468=>468, 469=>469, 470=>470, 471=>471, 472=>472, 473=>473, 474=>474, 475=>475, 476=>476, 477=>477, 478=>478, 479=>479, 480=>480, 481=>481, 482=>482, 483=>483, 484=>484, 485=>485, 486=>486, 487=>487, 488=>488, 489=>489, 490=>490, 491=>491, 492=>492, 493=>493, 494=>494, 495=>495, 496=>496, 497=>497, 498=>498, 499=>499, 500=>500,}
end
14 changes: 14 additions & 0 deletions bench/mri/bm_vm2_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
i = 0
while i<6_000_000 # while loop 2
case :foo
when :bar
raise
when :baz
raise
when :boo
raise
when :foo
i += 1
end
end

19 changes: 19 additions & 0 deletions bench/mri/bm_vm2_case_lit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
i = 0
@ret = [ "foo", true, false, :sym, 6, nil, 0.1, 0xffffffffffffffff ]
def foo(i)
@ret[i % @ret.size]
end

while i<6_000_000 # while loop 2
case foo(i)
when "foo" then :foo
when true then true
when false then false
when :sym then :sym
when 6 then :fix
when nil then nil
when 0.1 then :float
when 0xffffffffffffffff then :big
end
i += 1
end
9 changes: 9 additions & 0 deletions bench/mri/bm_vm2_defined_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Object
define_method(:m){}
end

i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m; m; m; m; m; m; m; m;
end
6 changes: 6 additions & 0 deletions bench/mri/bm_vm2_dstr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
i = 0
x = y = 'z'
while i<6_000_000 # benchmark loop 2
i += 1
str = "foo#{x}bar#{y}baz"
end
6 changes: 6 additions & 0 deletions bench/mri/bm_vm2_eval.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
eval("1")
end

9 changes: 9 additions & 0 deletions bench/mri/bm_vm2_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def m
nil
end

i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m; m; m; m; m; m; m; m;
end
12 changes: 12 additions & 0 deletions bench/mri/bm_vm2_method_missing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class C
def method_missing mid
end
end

obj = C.new

i = 0
while i<6_000_000 # benchmark loop 2
i += 1
obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m;
end
9 changes: 9 additions & 0 deletions bench/mri/bm_vm2_method_with_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def m
nil
end

i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m{}; m{}; m{}; m{}; m{}; m{}; m{}; m{};
end
9 changes: 9 additions & 0 deletions bench/mri/bm_vm2_mutex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'thread'

m = Mutex.new

i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m.synchronize{}
end
5 changes: 5 additions & 0 deletions bench/mri/bm_vm2_newlambda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
lambda {}
end
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ def m
o1 = C1.new
o2 = C2.new

i=0
while i<6000000 # benchmark loop 2
i = 0
while i<6_000_000 # benchmark loop 2
o = (i % 2 == 0) ? o1 : o2
o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
i+=1
i += 1
end
Loading