I would like to see some source code or maybe a link to some that gives at least a stub for writing ruby gems in the C languages (C++?? is that possible too?)
Also, some of you may know that Facebook compiles some of their code natively as php extensions for better performance. Is anyone doing this in Rails? If so, what has been your experience with it? Have you found it to be useful?
Thanks.
Edit:
I guess I’ll answer my own question with some stuff I learned today but I’m going to leave the question open for another answer because I’d like to see what others have to say on this topic
Ok, so I sat down a buddy of mine that is good with C. I have been showing him Ruby and he digs it. When we met last night I told him that you could write Ruby gems in C, which intrigued him. Here is what we found:
Tutorials/Examples
http://www.eqqon.com/index.php/Ruby_C_Extension
http://drnicwilliams.com/2008/04/01/writing-c-extensions-in-rubygems/
http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
ruby-doc (ruby.h source code)
http://ruby-doc.org/doxygen/1.8.4/ruby_8h-source.html
Here is some source code that we wrote to test it out as well:
Open up a terminal:
Then you put this code in extconf.rb
Save the file then write MyTest.c
From the prompt you then need to create a Makefile by running extconf.rb:
You can then test it out:
We did a benchmark test and had ruby add 3 and 4 together 10 million times and then make a call to our C extension 10 million times as well. The result was that using only ruby it took 12 seconds to complete this task while using the C extension only took 6 seconds! Also note, that most of this processing is handing the job off to C to complete the task. In one of those tutorials the writer used recursion (Fibonacci sequence) and reported that the C extension took 51 times faster!