# Total much slower in version 10

Issue introduced in version 10, fixed in 10.0.2

Compilation nowadays may give very fast functions. Here is an example for finding the sum of a list of machine numbers, just as the built-in function Total:

myTotal =   Compile[{{lst, _Real, 1}},
Module[{s = 0.}, Do[s = s + x, {x, lst}]; s],
CompilationTarget -> "C"];

lst = RandomReal[{0, 1}, {10^7}];
myTotal[lst] == Total[lst]
(*True *)


In Mathematica 10, I noted the surprising fact that the function myTotal is more than three times as fast as Total:

Do[myTotal[lst], {500}] // Timing (* {4.758031, Null} *)
Do[Total[lst], {500}] // Timing (* {16.052503, Null} *)


In Mathematica 9, they are as fast. So in Mathematica 10 (on Windows), Total is more than 3 times slower than in Mathematica 9, fortunately of course still very fast. What could be the reason for this slowdown?

• It's a known issue, reported and under investigation. Oct 15, 2014 at 15:55
• @DanielLichtblau Is it at this point decided whether there'll be a 10.0.2? Or was 10.0.1 the last 10.0.x version? Oct 15, 2014 at 16:05
• There are so many slow-downs in M10 that there have to me more bug-fix releases. I just go on mostly with V9 for the time being. Groetjes, Rolf Oct 15, 2014 at 16:11
• @Szabolcs I believe there will be a 10.0.2 but my beliefs sometimes depart from the real world. Oct 15, 2014 at 18:02
• Just a note, Total is more precise then the direct summation. Oct 15, 2014 at 19:07

Until this issue gets fixed by WRI you can use Tr instead of Total

Do[myTotal[lst], {500}] // Timing
Do[Total[lst], {500}] // Timing
Do[Tr[lst], {500}] // Timing

{5.241634, Null}
{16.161704, Null}
{5.194833, Null}

myTotal[lst] == Total[lst] == Tr[lst]

True