I have to look at some source code or maybe there is a link for something that is a stub to write at least one rubber gem C language (C ++ ??) Is this also possible?)
Besides, some of you know that Facebook has some of its code originally designed for PHP extensions Is compiled in the form. Does anyone do this in the railways? If so, what is the experience?
Edit: I think that today I will answer my question with a few things I learned, but I am about to open the question for another answer because I see this I want to tell others about this topic.
OK, so I sit with my friend Which is good with C I'm showing him Ruby and he digs it. When we met last night I told them that you can write Ruby Gems in C, who amazed her. Here we have found:
Tutorials / Examples
Ruby-Doctor (Ruby H Source Code)
Here are some source code that we have written:
Open Terminal:
Speedy> mkdir MyTest Sign> CD MIMET prompts> gedit extconf.rb
Then you enter this code in extconf.rb
#ModeMKMF which is the makefile for Ruby Extensions Used to make, it requires 'MKMF' # this Enter a name extension_name = 'mytest' # Destination DEIR_config (extension_name) # create create_makefile (extension_name)
Save the file then type MyTest.c
#include "ruby.h" // To store an internal information and reference about the module, set a location for MyTest = Qnil; // Prototype for initialization method - Ruby is called, you do not zero to INM_ETEST (); // Our method is already based on 'method_' prototype methods for 'test1' VALUE method_test1 (VALUE self); VALUE method_add (VALUE, VALUE, VALUE); // This module zero Init_mytest () initialization method (MyTest = rb_define_module ( "MyTest"); Rb_define_method (MyTest, "test1", method_test1, 0); Rb_define_method (MyTest, add "", method_add, 2) to;} / / Our 'test1' method .. It returns the value of '10' for now VALUE method_test1 (VALUE self) {int x = 10; return INT2NUM (x);} // This is the method we have added parameter has been added to check the VALUE parameter method_add (VALUE self, VALUE first, VALUE seconds) {int a = NUM2INT (first); Int b = NUM2INT (second); return INT2NUM (a + b);} prompt, you can run EXT Conf.rb Makefile needs to:
prompt> ruby extconf.rb prompt> gt; prompt & gt;
You can test it: MyTest irb> 3, 4 = & gt; 7
In the iRb irb> gt; mytest 'irb & gt; we did a benchmark test and Ruby had added 10 million times 3 and 4 and then call 10 million times our C extensions. The result was that it used to take 12 seconds to complete this task using only Rabbi, while using C extension only took 6 seconds! Also, keep in mind that most of this processing is handing over jobs to C to complete this task. In one of the tutorial author used recycling (Fibonaci sequence) and reported that several extensions taken 51 times faster!
Comments
Post a Comment