I'm a geek: hello, world in lua in ruby
> require "rubygems"
> require "rufus/lua"
> s = Rufus::Lua::State.new
> s.eval("print('Hello LUA')")
Hello LUA
=> nil
> require "rubygems"
> require "rufus/lua"
> s = Rufus::Lua::State.new
> s.eval("print('Hello LUA')")
Hello LUA
=> nil
I’ve made my way through across the vast Western desert and am at the foot of the great mountains that surround the nameless city, the destination of my pilgrimage. The great city that is only shown on maps as temenos – “holy precinct”. No roads, no landmarks. Simply the city beyond the mountains.
That’s not to say that it’s mysterious – aspects of it are, certainly, but it is the destination of countless pilgrimages like my own. By ancient law, however, neither it nor its patron gods are ever named, and no map of its features shall ever leave its walls. Just as no building is allowed to mar the natural beauty of the surrounding mountains, or the barren wastes of the desert outside.
I have no supplies left. Pilgrims are allowed to carry only enough to sustain themselves through the desert. Beyond this point, the only drink we are allowed is water from the mountain streams, and food left by monks at small shrines along the holy path.
One more week, and I’m there. I’m told this is the easier part – normally the final stretch would seem the longest, but the beauty and stimulation of the mountains makes time pass by quicker after the endless stretches of the Western desert.
I’ve stopped at the first shrine. An almost invisible statue tucked underneath a small outcropping of rock. There are flowers placed at its feet, and fruit and prayer beads. Thankfully the fruit shows absolutely no sign of spoil. I eat as much as I can, and bury the stems and inedbile skins a short ways away.
I return, and rest a while. Now’s probably a good idea as any to give a quick overview of my goal: the nameless city.
It was founded ages ago by a secretive cult. Little is known about them or their practices, or even their beliefs save for one thing: they worship two gods, male and female. Much like the city they founded, the gods themselves are nameless, or at least their names have never been shared with outsiders. They are described simply as the Man in Red and the Lady in White. Of course, myth tells that the city was founded by the gods themselves, but scattered historical docoments suggests that the cult existed prior to its founding.
Over time, the city grew. Slowly, due to its secluded location and it remained secretive, trading little with other cities on the continent . Periodically, however, traveling monks from its church would visit distant cities and speak with their holy men.
Anyways, long story short, eventually other religions started sending their own monks to check out this mysterious city. It came to be known as a holy place, a haven for the faithful of not just one religion, but any religion.
As time passed, even other temples sprouted up there, and grew, and fell, until the city had not just its two founding gods, but a strange pantheon of gods borrowed from other lands. And so, today, every god who has ever received a prayer from human lips is known there, and if tales are to be believed, every god ever known to man has at least one faithful worshipper there.
But there are ten that stand out: ten that, though I do not know the layout of the land, have had districts of the city named after them.
Three are of Egyptian origin:
One is a deified angel, Hebrew:
And the rest are of Greek or Roman origin:
And with ruby 1.9.2p0
sammael:rubyGP greay$ time ruby tinyGP.rb
real 0m12.546s
user 0m11.819s
sys 0m0.631s
MacRuby definitely seems to be the winner here…
I recently started reading A Field Guide to Genetic Programming … Barely in to it at all yet, but I’ve decided to rewrite the sample code (TinyGP) in Ruby. Because I like Ruby better than Java.
It’s very short. And the (very rough) ruby implementation w/o much anything special done to it is quite a bit shorter – down from 12KB to 8, and I really didn’t take anything out. That’s just the extra cruft that Java requires. For all I know the ruby implementation is orders of magnitude slower, though, I don’t know. Hell, I’ve barely tested it so I don’t even know it works.
The code’s @ github.
I really haven’t done much any performance tuning, but MY GOD.
sammael:rubyGP greay$ time ruby tinyGP.rb
real 0m26.821s
user 0m25.995s
sys 0m0.647s
sammael:rubyGP greay$ time java tiny_gp 23 sin-data.txt
real 0m0.495s
user 0m0.658s
sys 0m0.074s
sammael:rubyGP greay$ time macruby tinyGP.rb
real 0m1.199s
user 0m1.369s
sys 0m0.045s
This is just creating a population of 10000 individuals; nothing fancy. using OS X’s builtin (I think; I may have upgraded) ruby - MRI ruby 1.8.7, to be exact, that’s 26 seconds. Any amount of tuning I could throw at it, I don’t think I could get it down to the original java implementation’s < 0.5 seconds. Even if I’m doing something completely braindead, that’s a nearly 60x difference.
So I decided to try out MacRuby. I heard it’s better; it’s based on 1.9 and has a whole bunch of exciting things about it. LLVM! Integration w/the objective C runtime! And it’s fast! ~ 1.2 seconds! That’s waaaay better than the original ruby run, and it’s the exact same code. It’s still 3x slower than the java implementation, but like I said, I’ve done little to no tuning yet. But I’m happy w/3x slower for the time being… I want to play around w/the code a bit before I bother making it faster.