From: "Bartosz DziewoƄski" Date: 2012-08-01T18:40:11+09:00 Subject: Re: String Handling in Ruby 2012/8/1 Tridib Bandopadhyay : > 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? 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). -- Matma Rex