ffi-life
by Andrea Fazzi http://github.com/remogatto/ffi-life
ffi-life
is yet another implementation of The Game Of Life. The program is derived from my solution to Ruby Quiz #193. The interesting thing about ffi-life
is that it is a first real usage example of ffi-inliner a library to run C code from Ruby through Ruby-FFI. ffi-life
is shipped with a naive benchmark that compares the fast ffi-inliner
version against the pure Ruby version (see the BENCHMARKS section below). A little injection of portable C for a big improvement in speed!
-
Text based!
-
It uses
ffi-inliner
for very fast cells generation -
It is multiVM: give it a whirl with JRuby and appreciate how fast is it!
Simply open a terminal and run:
ffi-life
For more options execute:
ffi-life --help
-
ffi-inliner >= 0.2.1
git clone git://github.com/remogatto/ffi-life cd ffi-life rake gem:install
Here below there are some benchmark results running ffi-life with MRI Ruby 1.8.7 on my MacBook Core 2 2.16GHz.
andrea@ganimoide:~/src/ffi-life$ ruby bench/bench.rb user system total real [ffi-inliner] w: 100 h: 100 ticks: 10 1.450000 0.220000 1.670000 ( 1.696030) [ffi-inliner[ w: 60 h: 60 ticks: 10 0.520000 0.060000 0.580000 ( 0.584314) user system total real [ruby] w: 100 h: 100 ticks: 10 5.200000 0.560000 5.760000 ( 5.812291) [ruby] w: 60 h: 60 ticks: 10 1.860000 0.210000 2.070000 ( 2.086663)
And it’s even faster on JRuby!
andrea@ganimoide:~/src/ffi-life$ jruby bench/bench.rb user system total real [ffi-inliner] w: 100 h: 100 ticks: 10 0.970000 0.000000 0.970000 ( 0.970000) [ffi-inliner[ w: 60 h: 60 ticks: 10 0.310000 0.000000 0.310000 ( 0.310000) user system total real [ruby] w: 100 h: 100 ticks: 10 2.100000 0.000000 2.100000 ( 2.100000) [ruby] w: 60 h: 60 ticks: 10 0.692000 0.000000 0.692000 ( 0.692000)
(The MIT License)
Copyright © 2009 Andrea Fazzi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.