10-16-2009 07:24 AM
Colleagues,
Just would like to measure the performance of Transpose 2D Array function and got something strange:
Now results:
Is any rational explanation exists - why Time 1 is equal to zero?
Compare with multiply - here we will get nearby same time:
Probably bug?
Andrey.
10-16-2009 07:52 AM - edited 10-16-2009 07:57 AM
Andrey Dmitriev wrote:Probably bug?
If the result is correct, it cannot be a bug. 🙂
It could be an optimization. I thought I heard somewhere that transpose does not actually touch the data, but just adds a flag to reverse the order of the indices. (Similarly, reverse array does not reverse the data in memory, just adds a flag to run the index backwards (see first comment here)).
Certain code constructs, e.g. the while loop in the second part, might force it to do an explicit transpose.
Of course this is all just guessing. I am sure somebody more knowledgeable will chime in. 😉
10-16-2009 08:21 AM
Andrey,
I would expect time one to be zero most of the time if the transpose time is well under a millisecond. If transpose works by switching indices rather than moving the data, the time should only be dependent on the number of dimensions rather than the size of the array.
I replaced your while loop with a for loop. The time does not change until the value of N exceeds 1000000. For any value of N the second and subsequent runs are much faster than the first. I suspect that with constant folding and compiler optimization, this method of timing may not be very meaningful.
Lynn