#1048: Performance of Hash with an Array as a key ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 0.9 Component: MacRuby | Resolution: Keywords: | ----------------------------------+----------------------------------------- Changes (by yasuimao@…): * status: closed => reopened * resolution: fixed => Comment: I downloaded the latest nightly (0.9 12/17/2010) and further tested this issue. This time, I tested this with more than 1 file. The two scripts are following: '''1 File repeated 10 times''' {{{ hash = Hash.new(0) n = 1 10.times do |i| text = File.open("test.txt").read words = text.scan(/\w+/) (words.length - n).times do |i| hash[words[i..n+i].join(" ")] += 1 end end }}} '''Multiple files''' {{{ require 'find' hash = Hash.new(0) n = 1 Find.find(dir) do |file| next if File.extname(file) != ".txt" text = File.open(file).read words = text.scan(/\w+/) (words.length - n).times do |i| hash[words[i..n+i].join(" ")] += 1 end end }}} Both tests are repeated with String as a key and Array as a key (the sample scripts are with String as a key). {{{ String (Str): hash[words[i..n+i].join(" ")] += 1 Array (Ary): hash[words[i..n+i]] += 1 }}} For testing I used the following files: {{{ 1 file - 8,000 words 10 files - 79,000 words 18 files - 150,000 words }}} Also each test was repeated with different number of array elements 2 (n = 1), 3 (n = 2), and 4 (n = 3). '''Results - Ruby 1.8.7''' {{{ n 1 2 3 1 F rep - Str 0.51 0.54 0.58 1 F rep - Ary 0.67 0.70 0.72 10 F - Str 0.63 0.75 0.72 10 F - Ary 0.63 0.67 0.68 18 F - Str 1.19 1.39 1.43 18 F - Ary 1.36 1.37 1.41 }}} '''MacRuby 0.9 nightly 12/17/2010''' {{{ n 1 2 3 1 F rep - Str 1.73 1.84 1.96 1 F rep - Ary 1.62 2.04 2.27 10 F - Str 2.21 2.53 2.46 10 F - Ary 7.28 20.83 29.15 18 F - Str 4.35 4.64 5.10 18 F - Ary 24.68 88.95 131.77 }}} I'm wondering if this issue is still persisting or due to my poor scripts. -- Ticket URL: <http://www.macruby.org/trac/ticket/1048#comment:4> MacRuby <http://macruby.org/>