public
Last active

  • Download Gist
01_bench_fractal.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/usr/local/bin/ruby
 
BAILOUT = 16
MAX_ITERATIONS = 1000
 
def fractal
puts "Rendering"
y = -39
while y <= 39
puts
x = -39
while x <= 39
i = iterate(x/40.0,y/40.0)
if (i == 0)
print "*"
else
print " "
end
x+=1
end
y+=1
end
end
 
def iterate(x,y)
cr = y-0.5
ci = x
zi = 0.0
zr = 0.0
i = 0
while(1)
i += 1
temp = zr * zi
zr2 = zr * zr
zi2 = zi * zi
zr = zr2 - zi2 + cr
zi = temp + temp + ci
return i if (zi2 + zr2 > BAILOUT)
return 0 if (i > MAX_ITERATIONS)
end
end
 
i = 0
while i < 10
time = Time.new
fractal
puts
puts "Ruby Elapsed %f" % (Time.new - time)
i+=1
end
02_jruby_tenth_run.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
Rendering
 
*
*
*
*
*
***
*****
*****
***
*
*********
*************
***************
*********************
*********************
*******************
*******************
*******************
*******************
***********************
*******************
*******************
*********************
*******************
*******************
*****************
***************
*************
*********
*
***************
***********************
* ************************* *
*****************************
* ******************************* *
*********************************
***********************************
***************************************
*** ***************************************** ***
*************************************************
***********************************************
*********************************************
*********************************************
***********************************************
***********************************************
***************************************************
*************************************************
*************************************************
***************************************************
***************************************************
* *************************************************** *
***** *************************************************** *****
****** *************************************************** ******
******* *************************************************** *******
***********************************************************************
********* *************************************************** *********
****** *************************************************** ******
***** *************************************************** *****
***************************************************
***************************************************
***************************************************
***************************************************
*************************************************
*************************************************
***************************************************
***********************************************
***********************************************
*******************************************
*****************************************
*********************************************
**** ****************** ****************** ****
*** **************** **************** ***
* ************** ************** *
*********** ***********
** ***** ***** **
* * * *
Ruby Elapsed 0.192000
03_bench_fractal.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
 
 
public class bench_fractal extends RObject {
public static void main(String[] args) {
new bench_fractal()._main_();
}
 
public void _main_() {
RObject $last = RNil;
$last = bench_fractal.BAILOUT = new RFixnum(16L);
$last = bench_fractal.MAX_ITERATIONS = new RFixnum(1000L);
RObject i = RNil;
$last = i = new RFixnum(0L);
while (i.$less(new RFixnum(10L)).toBoolean()) {
RObject time = RNil;
$last = time = new RTime();
$last = this.fractal();
$last = this.puts();
$last = this.puts(new RString("Ruby Elapsed %f")
.$percent(new RTime().$minus(time)));
$last = i = i.$plus(new RFixnum(1L));
;
}
$last = RNil;
;
}
 
public static RObject BAILOUT = RNil;
public static RObject MAX_ITERATIONS = RNil;
 
public RObject fractal() {
RObject $last = RNil;
$last = this.puts(new RString("Rendering"));
RObject y = RNil;
$last = y = new RFixnum(-39L);
while (y.$less$equal(new RFixnum(39L)).toBoolean()) {
$last = this.puts();
RObject x = RNil;
$last = x = new RFixnum(-39L);
while (x.$less$equal(new RFixnum(39L)).toBoolean()) {
RObject i = RNil;
$last = i = this.iterate(x.$div(new RFloat(40.0)), y
.$div(new RFloat(40.0)));
if (i.$equal$equal(new RFixnum(0L)).toBoolean()) {
$last = this.print(new RString("*"));
} else {
$last = this.print(new RString(" "));
}
$last = RNil;
$last = x = x.$plus(new RFixnum(1L));
;
}
$last = RNil;
$last = y = y.$plus(new RFixnum(1L));
;
}
$last = RNil;
;
return $last;
}
 
public RObject iterate(RObject x, RObject y) {
RObject $last = RNil;
RObject cr = RNil;
$last = cr = y.$minus(new RFloat(0.5));
RObject ci = RNil;
$last = ci = x;
RObject zi = RNil;
$last = zi = new RFloat(0.0);
RObject zr = RNil;
$last = zr = new RFloat(0.0);
RObject i = RNil;
$last = i = new RFixnum(0L);
while (new RFixnum(1L).toBoolean()) {
$last = i = i.$plus(new RFixnum(1L));
RObject temp = RNil;
$last = temp = zr.$times(zi);
RObject zr2 = RNil;
$last = zr2 = zr.$times(zr);
RObject zi2 = RNil;
$last = zi2 = zi.$times(zi);
$last = zr = zr2.$minus(zi2).$plus(cr);
$last = zi = temp.$plus(temp).$plus(ci);
if (zi2.$plus(zr2).$greater(bench_fractal.BAILOUT).toBoolean()) {
$last = i;
return $last;
}
$last = RNil;
if (i.$greater(bench_fractal.MAX_ITERATIONS).toBoolean()) {
$last = new RFixnum(0L);
return $last;
}
$last = RNil;
;
}
$last = RNil;
;
return $last;
}
}
04_fastruby_tenth_run.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
Rendering
 
*
*
*
*
*
***
*****
*****
***
*
*********
*************
***************
*********************
*********************
*******************
*******************
*******************
*******************
***********************
*******************
*******************
*********************
*******************
*******************
*****************
***************
*************
*********
*
***************
***********************
* ************************* *
*****************************
* ******************************* *
*********************************
***********************************
***************************************
*** ***************************************** ***
*************************************************
***********************************************
*********************************************
*********************************************
***********************************************
***********************************************
***************************************************
*************************************************
*************************************************
***************************************************
***************************************************
* *************************************************** *
***** *************************************************** *****
****** *************************************************** ******
******* *************************************************** *******
***********************************************************************
********* *************************************************** *********
****** *************************************************** ******
***** *************************************************** *****
***************************************************
***************************************************
***************************************************
***************************************************
*************************************************
*************************************************
***************************************************
***********************************************
***********************************************
*******************************************
*****************************************
*********************************************
**** ****************** ****************** ****
*** **************** **************** ***
* ************** ************** *
*********** ***********
** ***** ***** **
* * * *
Ruby Elapsed 0.040000

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.