From: "Shot (Piotr Szotkowski)" Date: 2007-01-31T19:16:59+09:00 Subject: Benchmark results (was: Sane #hash implementation?) --dZHW955j1vPFHE0Q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Mauricio Fernandez: > (The order of the elements in Hash#to_a can change.) Thanks for pointing this out, I fixed my specs and my code. > Try this, it's O(n ln n) but actually works Ok, I guess I have a question on what does exactly Benchmark results mean. Doesn=E2=80=99t the below mean hash_map_sort is actually a bit slower= than hash_sort? Also, to ask two basic, follow-up questions: which Benchmark time is the most significant one and is it more-or-less independent from other system load? (I guess the two runs wouldn=E2=80=99t differ as much any of t= he times was other-load-independent=E2=80=A6) $ cat block_hash.rb=20 require 'benchmark' require 'set' class Block < Set def hash_sort sort.hash end def hash_map_sort map {|a| a.hash}.sort.hash end end srand 1979 array =3D (0..1_000_000).sort_by {rand} Benchmark.bmbm do |b| b.report 'hash_sort' do Block.new(array).hash_sort end b.report 'hash_map_sort' do Block.new(array).hash_map_sort end end $ ruby block_hash.rb=20 Rehearsal ------------------------------------------------- hash_sort 8.000000 1.366667 9.366667 ( 6.208513) hash_map_sort 9.750000 1.500000 11.250000 ( 7.179749) --------------------------------------- total: 20.616667sec user system total real hash_sort 9.666667 1.100000 10.766667 ( 6.677047) hash_map_sort 9.566667 1.550000 11.116667 ( 6.809388) $ ruby block_hash.rb=20 Rehearsal ------------------------------------------------- hash_sort 8.133333 1.316667 9.450000 ( 5.746571) hash_map_sort 9.650000 1.766667 11.416667 ( 7.065570) --------------------------------------- total: 20.866667sec user system total real hash_sort 9.316667 1.100000 10.416667 ( 6.684088) hash_map_sort 9.450000 1.566667 11.016667 ( 6.796299) -- Shot --=20 It is a good morning exercise for a research scientist to discard a pet hypothesis every day before breakfast. It keeps him young. -- Konrad Lorenz --dZHW955j1vPFHE0Q Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFFwGy3i/mCfdEo8UoRAvnLAJ0QiS+/ytBcbnTdit+y9expErHT2gCgpkD8 7IMhLLOL0b39wshrBpMvqD0= =th1S -----END PGP SIGNATURE----- --dZHW955j1vPFHE0Q--