Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Array performance question

Reply
Thread Tools

Array performance question

 
 
Jim Menard
Guest
Posts: n/a
 
      02-27-2009
Here's a real Array performance mystery. I can't help my friend figure
this one out. He writes,

========

Is there a known bug in Ruby array performance? I spent a lot of time
yesterday boiling down the following example


http://blogs.codehaus.org/people/gei...with_ruby.html

only because I still can't believe I'm not doing something incredibly
stupid. (I'm a newbie, "Reluctant Rubyist")

I'm just not used to arrays behaving this way Anyone have any
insight?

========

He'd love a response in his blog, but with permission I'll copy
answers here over there. He's not a regular ruby-talk reader...yet.

Jim
--
Jim Menard, ,
http://www.io.com/~jimm/

 
Reply With Quote
 
 
 
 
William James
Guest
Posts: n/a
 
      02-28-2009
Jim Menard wrote:

> Here's a real Array performance mystery. I can't help my friend figure
> this one out. He writes,
>
> ========
>
> Is there a known bug in Ruby array performance? I spent a lot of time
> yesterday boiling down the following example
>
>
> http://blogs.codehaus.org/people/gei...with_ruby.html
>
> only because I still can't believe I'm not doing something incredibly
> stupid. (I'm a newbie, "Reluctant Rubyist")
>
> I'm just not used to arrays behaving this way Anyone have any
> insight?
>
> ========
>
> He'd love a response in his blog, but with permission I'll copy
> answers here over there. He's not a regular ruby-talk reader...yet.
>
> Jim


This variation exhibits the same behavior.


require 'benchmark'

class BufferContainer

def initialize( initial_data )
@buf = initial_data
end

def put_array( array )
@buf[0, array.size] = array
end
end

size = 999
the_array = (0..4).to_a

(1..3).each{|i|
size *= 10
a = [nil] * size

# RUN WITH THIS COMMENTED OUT FIRST
# a << 9

puts "size = #{ size } #{ a.size }"
puts Benchmark.measure {
10_000.times {
buf = BufferContainer.new( a )
buf.put_array( the_array )
}
}

}

 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      03-01-2009

On Feb 27, 2009, at 05:16 , Jim Menard wrote:

> Is there a known bug in Ruby array performance? I spent a lot of time
> yesterday boiling down the following example
>
> http://blogs.codehaus.org/people/gei...with_ruby.html


I don't have time to dig into this, but I believe he's hitting a GC
threshold by going over N objects.

 
Reply With Quote
 
Ryan Davis
Guest
Posts: n/a
 
      03-01-2009

On Feb 28, 2009, at 21:32 , Ryan Davis wrote:

>
> On Feb 27, 2009, at 05:16 , Jim Menard wrote:
>
>> Is there a known bug in Ruby array performance? I spent a lot of
>> time
>> yesterday boiling down the following example
>>
>> http://blogs.codehaus.org/people/gei...with_ruby.html

>
> I don't have time to dig into this, but I believe he's hitting a GC
> threshold by going over N objects.


Poke around gc.c and see what you can figure out. Also, look at the
1.9 version or through the changelog to find hints...

#ifndef GC_MALLOC_LIMIT
#if defined(MSDOS) || defined(__human68k__)
#define GC_MALLOC_LIMIT 200000
#else
#define GC_MALLOC_LIMIT 8000000
#endif
#endif


 
Reply With Quote
 
Thomas Enebo
Guest
Posts: n/a
 
      03-10-2009
Jim Menard wrote:
> Here's a real Array performance mystery. I can't help my friend figure
> this one out. He writes,
>
> ========
>
> Is there a known bug in Ruby array performance? I spent a lot of time
> yesterday boiling down the following example
>
>
> http://blogs.codehaus.org/people/gei...with_ruby.html
>
> only because I still can't believe I'm not doing something incredibly
> stupid. (I'm a newbie, "Reluctant Rubyist")
>
> I'm just not used to arrays behaving this way Anyone have any
> insight?
>
> ========
>
> He'd love a response in his blog, but with permission I'll copy
> answers here over there. He's not a regular ruby-talk reader...yet.
>
> Jim
>

I am betting Ryan is right about GC issues. JRuby does not fall down
doing this either (which probably also backs up the GC theory):

ruby ~/jruby/scripts/arr_ben.rb
size = 10000 10000
0.050000 0.000000 0.050000 ( 0.057190)
size = 100000 100000
0.660000 0.000000 0.660000 ( 0.67217
size = 1000000 1000000
34.430000 0.340000 34.770000 ( 35.562454)

jruby --server ~/jruby/scripts/arr_ben.rb
size = 10000 10000
0.372000 0.000000 0.372000 ( 0.266000)
size = 100000 100000
0.099000 0.000000 0.099000 ( 0.099000)
size = 1000000 1000000
0.154000 0.000000 0.154000 ( 0.154000)

-Tom


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance Tutorials Services - Boosting Performance by DisablingUnnecessary Services on Windows XP Home Edition Software Engineer Javascript 0 06-10-2011 02:18 AM
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Re: Strange array.array performance Maxim Khitrov Python 5 03-12-2009 12:48 AM
Strange array.array performance Maxim Khitrov Python 0 02-19-2009 06:52 PM
Web Form Performance Versus Single File Performance jm ASP .Net 1 12-12-2003 11:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57