mruby Presentation, now with structure
This is what happens when sarcasm goes too far: I end up doing a lightning talk. There's a warning for those who would be warned.
So I did this lightning talk. Not sure it was particularly easy to follow, so I thought I would do a follow up post. it has been described as a live coding talk; a misnomer since I only actually deleted lines. Consider these your slides.
How do I get it?
Get the git repository from github. Clone, cd into the directory and run "make". Job done (you need bison installed). It compiles pretty quickly.
What is mruby?
def fibbonacci(n) return 1 if n < 2 return fibbonacci(n - 1) + fibbonacci(n - 2) end puts fibbonacci 20
Bear in mind that mruby is still in an alpha stage. Some language features are missing, and the standard library support is not quite up to standard. But it does have an irb - called mirb. I'd suggest you create a directory, or use the examples directory provided to write your code in, but if you're just playing with the language, go to bin/mirb.
mruby can be used like normal ruby. You can run the above file with the mruby binary. But the fun comes with the compiler, mrbc. The compiler doesn't produce machine code - instead, it produces a C file. It is your job to then write more C code that uses your new ruby function.
I'm lazy though, and I don't need the C file, so I wrote a script to do that bit for me. Avert your eyes if you are allergic to nasty hacked together scriptlets. Pop this in a file called "compile_mruby" and run it with:
ruby ./compile_mruby fibber.rb
Note that this expects your code to be inside a folder inside the cloned mruby project (e.g. "examples"), so that you can access the binary from ../bin/mrbc
So, the reason you would compile this would be for the speed increase, right?
mruby, interpretedIPRUG:: $ time ../bin/mruby fibber.rb 10946 real 0m0.009s user 0m0.005s sys 0m0.002s
mruby, compiledIPRUG:: $ time ./fibber 10946 real 0m0.008s user 0m0.005s sys 0m0.002s
MRI ruby, 1.9.3, interpretedIPRUG:: $ time ruby fibber.rb 10946 real 0m0.158s user 0m0.084s sys 0m0.073s
Uhh, ok, so a massive improvement over normal ruby, but only 0.001 of a second improvement between compiled mruby and interpreted. Only ran it once - that's probably just normal inaccuracies. It's faster than MRI ruby though. So why would you bother compiling at all?
A compiled binary...-rwxr-xr-x 1 matthew staff 337K 6 Mar 00:21 fibber
... vs the a file and its interpreter-rw-r--r-- 1 matthew staff 110B 6 Mar 00:15 fibber.rb -rwxr-xr-x 1 matthew staff 571K 28 Feb 12:32 ../bin/mruby
... vs the file and MRI binary-rw-r--r-- 1 matthew staff 110B 6 Mar 00:15 fibber.rb -rwxr-xr-x 1 matthew staff 2.4M 25 Jun 2012 [...]/1.9.3-p194/bin/ruby
(this doesn't take into account standard libraries...)
This footprint size, and the ability to use compiled ruby directly in a C / C++ project, means mruby could be awesome for embedded systems. It's still in active developent and will be an interesting one to watch!