From: "Iñaki Baz Castillo" Date: 2011-07-02T00:50:46+09:00 Subject: Re: How to order Structs based on two fields 2011/7/1 Su Zhang : > The efficiency depends on how expensive it is to compute the key of the > elements. If the computation is non-trivial, then Array#sort_by would be > much faster because it caches the keys before the sort so that no > unnecessary computation is done (i.e., the key of each element is computed > exactly once). > > If, like it is in your case, the computation only involves several Fixnum > comparisons, Array#sort_by will most likely be slower as it needs to > allocate (cache) the key set prior to the actual sorting. > > For example, there should be a difference if the accessors themselves are > expensive. Something like: > >  def a >    sleep 0.01 >    @a >  end Thanks. However in my case the class is a Struct and I add no complexity to accessor. In fact I just use: KK = Struct.new(:a, :b) kk1 = KK.new(10,20) -- Iñaki Baz Castillo