Created
February 1, 2017 06:30
-
-
Save headius/2a8de5eb6adb115acb4649b698e2f6d3 to your computer and use it in GitHub Desktop.
mandelbrot(750) on JRuby with and without a tweaked Graal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/graal-core $ jruby -v mandelbrot.rb | |
jruby 9.1.8.0-SNAPSHOT (2.3.1) 2017-01-25 2b97d78 Java HotSpot(TM) 64-Bit Server VM 9-ea+152 on 9-ea+152 +indy +jit [linux-x86_64] | |
1.4988730000000001 | |
0.875144 | |
0.6610520000000001 | |
0.666915 | |
0.67083 | |
0.658069 | |
0.6749970000000001 | |
0.667617 | |
0.657871 | |
0.674458 | |
0.66978 | |
0.662599 | |
0.667123 | |
0.658297 | |
0.658273 | |
0.6735150000000001 | |
0.6749130000000001 | |
0.664429 | |
0.660354 | |
0.666023 | |
~/projects/graal-core $ JAVACMD='mx' JAVA_OPTS="vm -XX:+UseJVMCICompiler $JAVA_OPTS" jruby mandelbrot.rb | |
0.960151 | |
0.101854 | |
0.076482 | |
0.44248 | |
0.09597800000000001 | |
0.094159 | |
0.075928 | |
0.076088 | |
0.076514 | |
0.07663 | |
0.076598 | |
0.080044 | |
0.07718 | |
0.07926 | |
0.088762 | |
0.076311 | |
0.076569 | |
0.077234 | |
0.076789 | |
0.076705 | |
~/projects/graal-core $ cat mandelbrot.rb | |
def mandelbrot(size) | |
sum = 0 | |
byte_acc = 0 | |
bit_num = 0 | |
y = 0 | |
while y < size | |
ci = (2.0*y/size)-1.0 | |
x = 0 | |
while x < size | |
zrzr = zr = 0.0 | |
zizi = zi = 0.0 | |
cr = (2.0*x/size)-1.5 | |
escape = 0b1 | |
z = 0 | |
while z < 50 | |
tr = zrzr - zizi + cr | |
ti = 2.0*zr*zi + ci | |
zr = tr | |
zi = ti | |
# preserve recalculation | |
zrzr = zr*zr | |
zizi = zi*zi | |
if zrzr+zizi > 4.0 | |
escape = 0b0 | |
break | |
end | |
z += 1 | |
end | |
byte_acc = (byte_acc << 1) | escape | |
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 | |
sum ^= byte_acc | |
byte_acc = 0 | |
bit_num = 0 | |
elsif (x == size - 1) | |
byte_acc <<= (8 - bit_num) | |
#print byte_acc.chr | |
sum ^= byte_acc | |
byte_acc = 0 | |
bit_num = 0 | |
end | |
x += 1 | |
end | |
y += 1 | |
end | |
sum | |
end | |
20.times { | |
t = Time.now | |
mandelbrot(750) | |
puts Time.now - t | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment