This is a multi-part message in MIME format.
--------------080706020308050501090503
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hello Rubyists,
I've bumped into a performance issue when comparing a hash via an
iterator. Included is the profiler output.
Question:
Why is
foo bar @bigHumonguosHash) : apple ? orange
Soooo much slower than (almost 100%)
foo bar.id @bigHumongousHash.id) : apple ? orange
What does ruby do internally when it is asked to compare objects via
references (especially huge hashes, tens of thousands of records indexed
by strings)..
p.s. Notice that I just put into use all the "Ruby ways" which were
discussed earlier? ;-)
--
Wai-Sun "Squidster" Chia
RHCE/Professional Services
Linux/Unix/Web Developer
--------------080706020308050501090503
Content-Type: text/plain;
name
rea.profile"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename
rea.profile"
./profiler.rb
Line time% time count
1 module LineProfiler__
2 lastNow tart rocess.times[0]
3 lastFile (toplevel)'
4 lastLine
5 lastTimes 0.0]
6 lastCounts 0]
7 Files }
8
9 p roc { |event, file, line, id, binding, klass|
10 if event 'line'
11 now rocess.times[0]
12 lastTimes[ lastLine ] + ow - lastNow
13 lastCounts[ lastLine ] +
14 if lastFile ! ile
15 (lastTimes, lastCounts) iles.fetch(file) { |name|
16 Files[name] Array.new(10000, 0.0), Array.new(10000, 0) ]
17 }
18 lastFile ile
19 end
20 lastLine ine
21 lastNow rocess.times[0]
22 end
23 }
24
25 END {
26 set_trace_func nil
27 total rocess.times[0] - Start
28 total / 00.0 # convert to percent
29 f TDERR
30 for file in Files.keys.sort
31 f.printf("