# Mruby fastr than ruby 2.0 and jruby?

**URL:** <https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182>\
**Category:** ruby-talk\
**Created:** [18 February 2014 17:23 UTC](https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182 "2014-02-18T17:23:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [18 February 2014 17:23 UTC](https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182/1 "2014-02-18T17:23:42Z")

</div>

hello,  
trying this stupid code,

> **···**
>
> =========================  
> def a(p,j)  
> &nbsp;&nbsp;&nbsp;i=0  
> &nbsp;&nbsp;&nbsp;while i\<1000  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p+=j\*(j-1)\*(j-2)\*(j-3)\*(j-4)\*(j-5)\*(j-6)\*(j-7)\*(j-8)\*(j-9)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i+=1  
> &nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;p  
> end  
> def b(b)  
> &nbsp;&nbsp;starttime=Time.now if b  
> &nbsp;&nbsp;puts("start") if b  
> &nbsp;&nbsp;p=0  
> &nbsp;&nbsp;j=10  
> &nbsp;&nbsp;while j\<10000  
> &nbsp;&nbsp;&nbsp;p=a(p,j)  
> &nbsp;&nbsp;&nbsp;j+=1  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;endtime=Time.now if b  
> &nbsp;&nbsp;puts("end : p="+p.to\_s+ " "+ (endtime-starttime).to\_f.to\_s + " secs")  
> if b  
> end  
> b(false)  
> b(true)
> 
> ===============================  
> I get this strange result :
> 
> > jruby j.rb
> 
> start  
> end : p=9041028926052438935146265250228470208000000000 14.0 secs
> 
> > ruby j.rb
> 
> start  
> end : p=9041028926052438935146265250228470208000000000 26.663525 secs
> 
> > mruby j.rb
> 
> start  
> end : p=9.04102892605544e+45 2.34413399999999 secs
> 
> > jruby -v && ruby -v && mruby -v
> 
> jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java  
> HotSpot(TM) Client VM 1.6.0\_31) [Windows 7-x86-java]  
> ruby 2.0.0p0 (2013-02-24) [i386-mingw32]  
> mruby 1.0.0 (2014-01-10)
> 
> So mruby is it realy the faster ruby vm ?
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto3](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/yukihiro_matsumoto3/32/1988_2.png) [@Yukihiro\_Matsumoto3](https://rubytalk.org/u/Yukihiro_Matsumoto3)\
**Post date:** [18 February 2014 18:35 UTC](https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182/2 "2014-02-18T18:35:58Z")

</div>

Hi,

> So mruby is it realy the faster ruby vm ?

In general, no. This case is special, since mruby does not have  
Bignums and uses faster (and inaccurate) Floats instead.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

> **···**
>
> In message "Re: mruby fastr than ruby 2.0 and jruby ?" on Tue, 18 Feb 2014 18:23:42 +0100, Regis d'Aubarede \<lists@ruby-forum.com\> writes:
> 
> > # hello, trying this stupid code,
> > 
> > def a(p,j)  
> > &nbsp;&nbsp;i=0  
> > &nbsp;&nbsp;while i\<1000  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p+=j\*(j-1)\*(j-2)\*(j-3)\*(j-4)\*(j-5)\*(j-6)\*(j-7)\*(j-8)\*(j-9)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i+=1  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;p  
> > end  
> > def b(b)  
> > starttime=Time.now if b  
> > puts("start") if b  
> > p=0  
> > j=10  
> > while j\<10000  
> > &nbsp;&nbsp;p=a(p,j)  
> > &nbsp;&nbsp;j+=1  
> > end  
> > endtime=Time.now if b  
> > puts("end : p="+p.to\_s+ " "+ (endtime-starttime).to\_f.to\_s + " secs")  
> > if b  
> > end  
> > b(false)  
> > b(true)
> > 
> > ===============================  
> > I get this strange result :
> > 
> > > jruby j.rb
> > 
> > start  
> > end : p=9041028926052438935146265250228470208000000000 14.0 secs
> > 
> > > ruby j.rb
> > 
> > start  
> > end : p=9041028926052438935146265250228470208000000000 26.663525 secs
> > 
> > > mruby j.rb
> > 
> > start  
> > end : p=9.04102892605544e+45 2.34413399999999 secs
> > 
> > > jruby -v && ruby -v && mruby -v
> > 
> > jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java  
> > HotSpot(TM) Client VM 1.6.0\_31) [Windows 7-x86-java]  
> > ruby 2.0.0p0 (2013-02-24) [i386-mingw32]  
> > mruby 1.0.0 (2014-01-10)
> > 
> > So mruby is it realy the faster ruby vm ?
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [18 February 2014 19:55 UTC](https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182/3 "2014-02-18T19:55:34Z")

</div>

> > So mruby is it realy the faster ruby vm ?
> 
> In general, no. This case is special, since mruby does not have  
> Bignums and uses faster (and inaccurate) Floats instead.

Thank you for your response.

So I replace  
p+=j\*(j-1)\*(j-2)\*(j-3)\*(j-4)\*(j-5)\*(j-6)\*(j-7)\*(j-8)\*(j-9)  
by  
p+=(1.0\*j\*(j-1))/(1.0\*j\*j+1)

and  
&nbsp;&nbsp;p+=a(p,j)  
by  
&nbsp;&nbsp;p=a(1,j)

Then I get :

> mruby j.rb && ruby j.rb && jruby j.rb

start  
end : p=1000.89997999798 1.52808799999999 secs  
start  
end : p=1000.8999799979861 5.132293 secs  
start  
end : p=1000.89997999799 3.494 secs

Perhaps windows version give some strange degradation...

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 February 2014 18:36 UTC](https://rubytalk.org/t/mruby-fastr-than-ruby-2-0-and-jruby/69182/4 "2014-02-20T18:36:38Z")

</div>

another test with a sudoku resolver :

> mrbc sudoku.rb && ruby sudoku.rb && jruby sudoku.rb && mruby -b sudoku.mrb

duration 6.37931 secs, 0.637931 ms by resolution  
duration 13.161 secs, 1.3161 ms by resolution  
duration 27.4534860 secs, 2.74534860 ms by resolution

code : [https://gist.github.com/raubarede/9120207](https://gist.github.com/raubarede/9120207)

> **···**
>
> ====  
> adaptations for mruby:  
> \* int/int ==\> float in mruby , so convert (a/b) by (a/b).floor  
> \* here docs / DATA not implemented in mruby
> 
> original sudokutest is modified for doing backtracking
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
