I created an array of size 61 million and allocated two different kinds
of string in that array using a loop. One small string like "MAC" and
second a big string (like from a to z). And i tried to measure the time
of the whole process using Time function.
Strangely while allocating the small string the program takes 120
seconds whereas while allocating the big string it takes 65 seconds.
Can any one tell me why this time difference is going on?
OK now I have my own extension which allocates object. It takes 48
seconds to allocate 61 million number of strings in an array which my
extension creates whereas regular ruby takes 120 seconds to allocate
strings in a regular array. What makes the Ruby to take so long time to
allocate the string?
We don't know how your code looks, so we can only guess. My guess is
that there is a difference between rb_str_new() (or however you are
construncting the string) and rb_str_init (I think this is the method
used internally by Ruby to create new strings from Ruby code).
There is also the obvious overhead of Ruby method calls and closures
(something as simple as "100_000_000.times{}" takes over 10 seconds on
my machine, while the equivalent C code "for(int i=0; i<100000000;
i++){}" compiled with -O0 takes half a second).
OK now I have my own extension which allocates object. It takes 48
seconds to allocate 61 million number of strings in an array which my
extension creates whereas regular ruby takes 120 seconds to allocate
strings in a regular array. What makes the Ruby to take so long time to
allocate the string?
You did not even show your original code, let alone the modified
version. How can you expect we can answer these questions?
Cheers
robert
···
On Wed, Aug 1, 2012 at 5:02 AM, Tridib Bandopadhyay <lists@ruby-forum.com> wrote:
Thanks Henry that was very much helpful.
OK now I have my own extension which allocates object. It takes 48
seconds to allocate 61 million number of strings in an array which my
extension creates whereas regular ruby takes 120 seconds to allocate
strings in a regular array. What makes the Ruby to take so long time to
allocate the string?