From: Joe Van Dyk Date: 2005-08-14T03:18:16+09:00 Subject: Re: no clue On 8/12/05, William James wrote: > Faster yet: > > iter = 20_000 > > data = DATA.inject([]){|a,x| a << x.chomp} What is DATA? Does it have anything to do with __END__ at the bottom? Joe > times = [] > > h1={} > times << Time.now > > iter.times { > data.each{ |line| tmp = line.split(/\s*[:,]\s*/) > (0...tmp.size).step(2){ |i| h1[tmp[i].to_sym]=tmp[i+1] } > } > } > > > h2={} > times << Time.now > > iter.times { > data.each{ |line| line.split(/\s*[:,]\s*/).inject(false){|a,b| > if a then h2[a.to_sym]=b; a=false else a=b end } > } > } > > result_hash = {} > times << Time.now > > iter.times { > data.each{|line| line.scan(/(\w+)\s*:\s*([^, ]*)/) { |k, v| > result_hash[k.to_sym] = v } > } > } > > times << Time.now > > p result_hash == h2 && h2 == h1 > (1...times.size).each{|i| p times[i]-times[i-1]} > > __END__ > some_key: blah, some_other_key: more_blah, yet_other_key: yet_more_blah > key1:value1,key2: value2,key3 :value_3 , > key4:value4,key555555555:value55555 > x_position: 20, y_position: 40, z_position: 30,zz_position:85 > > > Output (on a slower computer): > true > 6.82 > 7.27 > 8.413 > > >