MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Tr[list] vs Plus@@list

  • To: mathgroup at
  • Subject: [mg73718] Tr[list] vs Plus@@list
  • From: "dimitris" <dimmechan at>
  • Date: Sun, 25 Feb 2007 04:41:12 -0500 (EST)

Can somebody explain me the difference in timing performances
between the settings Tr[list] and Plus@@list?

Thanks a lot!

lst[i_] := Table[Random[], {i}]

{Timing[Tr[lst[10^4]]; ], Timing[Tr[lst[10^5]]; ],
Timing[Tr[lst[10^6]]; ], Timing[Tr[lst[10^7]]; ]}

{{0.*Second, Null}, {0.030999999999999972*Second, Null},
{0.15600000000000003*Second, Null}, {2.0469999999999997*Second, Null}}

{Timing[Plus @@ lst[10^4]; ], Timing[Plus @@ lst[10^5]; ], Timing[Plus
@@ lst[10^6]; ], Timing[Plus @@ lst[10^7]; ]}

{{0.*Second, Null}, {0.04700000000000015*Second, Null}, {0.484*Second,
Null}, {4.922000000000001*Second, Null}}

  • Prev by Date: Re: How to manipulate globals in a function?
  • Next by Date: showing an expression equal to 0
  • Previous by thread: Re: Re: reliability function drawing
  • Next by thread: Re: Tr[list] vs Plus@@list