mruby is minimalistic Ruby, developed by Matz (Ruby’s creator) and
funded by the Japanese ministry of Economy.
I’ve been waiting for this to go public since Matz’ early announcements of him being working on it. This is very exciting.
Installing
$ git clone https://github.com/mruby/mruby
$ make
Compilation is a fantastic error-less breeze, around 20 seconds.
Hello mruby
Lets see how this thing should work.
|
Done. Quick sanity check for mruby, very cool. Lets try something more complicated.
|
No rubygems so no errors while requiring any of these, and we can confirm (unsurprisingly) that we can’t treat it like a normal ruby. So we get:
|
Yup, no benchmark, so lets use time. I’ve ported a benchmark sample from the computer language shootout, removing mruby incompatible things and bridging the gap between mruby and ruby so we can just toggle each and run.
You can take a look at it here: https://gist.github.com/2438540.
Its Not Faster
I had 0-knowledge about what mruby should do here. Since I’m familiar with Lua’s speed and mruby aiming for that space, I was hoping for a surprise.
A quick run shows that the mruby interpreter is considerably slower,
and giving off different results, I don’t care about that for now:
|
In mruby you can compile your code to bytecode. I’ve compiled it using
mrbc which also lives in bin into n-body.mrb and ran it above
using the -b flag: mruby -b.
Just a funny fact, if you dump the compiled content, for the magic number, you get:
|
The Real Fun Is Here
Lets look at what the executable mruby is, this is quite cool:
|
This shows why mruby is so awesome; you can embed it – and the perfect example for it is the mruby executable itself.
