On 2002.07.12, Tom Sawyer <transami / transami.net> wrote:
> > "junk#{x}morejunk" is much faster then "junk" << x << "morejunk"
> 
> oh, FYI, both of these are faster then "junk" + x + "morejunk"

Speaking of "faster" -- while determining "faster" by measuring
actual elapsed time might be an acceptance test of determining
"faster" ... is there any way in Ruby to ask the interpreter
about its internals: particularly the number of objects
constructed throughout its lifetime?

I imagine "junk#{x}morejunk" is faster than "junk" << x << "morejunk"
which is faster than "junk" + x + "morejunk" because of the number
of intermediate objects that need to be created for each of these.
Being able to write a test that says:

  total_objects_created = Kernel.total_objects_created
  # do some stuff
  new_total_objects_created = Kernel.total_objects_created
  approximate_number_of_objects_created_for_operation =
    new_total_objects_created - total_objects_created

The method that has the smallest value for
approximate_number_of_objects_created I imagine would
also be the "fastest" one with regard to elapsed time.
Probably also use the least system resources.

Just another idea for adding to my Test::Unit suites ...

-- Dossy

-- 
Dossy Shiobara                       mail: dossy / panoptic.com 
Panoptic Computer Network             web: http://www.panoptic.com/ 
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)