“junk#{x}morejunk” is much faster then “junk” << x << “morejunk”
oh, FYI, both of these are faster then “junk” + x + “morejunk”
~transami
···
On Thu, 2002-07-11 at 13:22, Tom Sawyer wrote:
Seems a little cleaner/clearer, but that’s IMHO of course Your
method is probably more efficient, since the one I mentioned creates
an intermediate array. I guess it depends on how performance critical
the code in question is.
actually joins faster. just tested it out. also discovered that:
thanks for all the help guys! i think i can speed up miter a bit just by
using join.
what i now do:
q = ‘’
arr.each_with_nindex do |x, n|
q << ‘junk’ << x << ‘morejunk’
q << ‘,’ if n != -1
end
how do you do it with join?
note: how i used to do it is probably a tad faster actually
Hmm, how about something like…
arr.collect { |x| ‘junk’ + x + ‘morejunk’ }.join(“,”)
?
Seems a little cleaner/clearer, but that’s IMHO of course Your
method is probably more efficient, since the one I mentioned creates
an intermediate array. I guess it depends on how performance critical
the code in question is.
–
Josh Huber
–
~transami
“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
– Benjamin Franklin
–
~transami
“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
– Benjamin Franklin
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:
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 …
“junk#{x}morejunk” is much faster then “junk” << x << “morejunk”
oh, FYI, both of these are faster then “junk” + x + “morejunk”
–
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)