From: Douglas Seifert Date: 2010-09-13T01:29:23+09:00 Subject: Re: Key Associated w/ Maximum Value in Hash --00151743fa1081fff10490127828 Content-Type: text/plain; charset=ISO-8859-1 For fun: http://www.pastie.org/1153968 $ ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux] $ ruby max_hash_value.rb {0=>-18, 1=>-5, 2=>-31, 3=>44, 4=>-13, 5=>-1, 6=>23, 7=>5, 8=>22, 9=>37} user system total real max 0.110000 0.000000 0.110000 ( 0.270811) max 1.9.X 0.090000 0.000000 0.090000 ( 0.242181) select 0.430000 0.000000 0.430000 ( 1.270329) select (cache max) 0.080000 0.000000 0.080000 ( 0.147179) sort_by 0.160000 0.000000 0.160000 ( 0.438671) invert 0.080000 0.000000 0.080000 ( 0.279259) invert (cache max) 0.060000 0.000000 0.060000 ( 0.155440) On Fri, Sep 10, 2010 at 5:20 AM, Ben Giddings wrote: > On Sep 9, 2010, at 23:00, Timothy Baron wrote: > >> I've tried several of these approaches, and they all work well. I'm >> curious, too, about which is the fastest, but for my small hashs, >> there's no noticable difference. >> > > Don't bother optimizing it for speed unless you are sure it's a bottleneck. > Choose whichever option is the most readable and maintainable. > > Ben > > > > --00151743fa1081fff10490127828--