Message Boards Message Boards


Timing a calculation within a loop

Posted 8 years ago
0 Replies
0 Total Likes

I am attempting a somewhat long calculation and would like to get timing statistics on each calculation that is performed within a loop. My current implementation, which is not working, looks like this:

T = AbsoluteTime[];
t  = AbsoluteTime[];

fname = "...\\output.tsv";
Put[ fname ];
For[ i = 1, i < maximum, i++,
    (* Calculations that are very time consuming matrix operations *)

t = AbsoluteTime[] - t;
PutAppend[ t , fname];
T = AbsoluteTime[] - T;

The output in Mathematica looks like (first t values, then T): "0.019978 0.020020 ....


The output to the file looks like: 0.0199729.94155819549696 0.0200207.38343434343434

There are two problems: First, the t values are not accurate. They are at least an order of magnitude smaller than expected. Second, the outputs to the .tsv file don't match the values output within the Mathematica notebook; the sum of the t's isn't equal to T.


POSTED BY: Jon Spalding
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract