append() versus &=

new topic     » topic index » view thread      » older message » newer message

Hello,

Who was it that recently said that append() is faster than &= ?
I have written a benchmark program that seems to prove otherwise.
Let me know if there is a flaw in my program or if I misunderstood
or what.

----- TESTED CODE -------
constant its = 100000
sequence s
atom t
object temp

constant frmt = "%0.03f"

printf (1, "Appending benchmarks for Euphoria using %d iterations\n", its)

puts (1, "\nAppending integers...\n")

puts (1, "append():\t")
s = {}
t=time()
for i = 1 to its do
  s = append (s, rand (its))
end for
t = time() - t
printf (1, frmt & "\n", t)

puts (1, "&=:\t\t")
s = {}
t = time ()
for i = 1 to its do
  s &= rand (its)
end for
t = time() - t
printf (1, frmt & "\n", t)


constant chars = 20
printf (1, "\nAppending strings (%d characters)...\n", chars)
puts (1, "append():\t")
s = {}
temp = repeat (255,chars)
t=time()
for i = 1 to its do
  s = append (s, rand (temp))
end for
t = time() - t
printf (1, frmt & "\n", t)

puts (1, "&=:\t\t")
s = {}
t = time ()
for i = 1 to its do
  s &= {rand (temp)}
end for
t = time() - t
printf (1, frmt & "\n", t)


puts (1, "\nAppending complex sequences eg: {a,{a,{a}}}...\n")
puts (1, "append():\t")
s = {}
temp = {its,{its,{its}}}
t=time()
for i = 1 to its do
  s = append (s, rand (temp))
end for
t = time() - t
printf (1, frmt & "\n", t)

puts (1, "&=:\t\t")
s = {}
t = time ()
for i = 1 to its do
  s &= {rand (temp)}
end for
t = time() - t
printf (1, frmt & "\n", t)
-------END CODE-------

later,
Lewis Townsend
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at
http://profiles.msn.com.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu