Message Boards Message Boards

0
|
4031 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Strange behavior of Transpose in Mathematica 12.3 for Windows

Transpose is used in tree different ways. It spents much time, except when it is added AbsoluteTiming. Why? Thanks. Guillermo

Very slow

Transpose[{Range[10^5], Range[10^5]}]

slow

Evaluate[Transpose[{Range[10^5], Range[10^5]}]]

Fast

Evaluate[Transpose[{Range[10^5], Range[10^5]}]] // AbsoluteTiming
4 Replies
Posted 2 years ago

Rohit:

Thanks. I can trust the space-time continuum again. :)

POSTED BY: Mike Besso
Posted 2 years ago

@Rohit:

Any idea why Evaluate runs in about 60% of the time as the non-evaluate version?

THANKS

POSTED BY: Mike Besso
Posted 2 years ago

Hi Mike,

The times are small and AbsoluteTiming is elapsed time which depends on what else is running on the machine. Replace AbsoluteTiming with RepeatedTiming to get a more accurate measurement. There is very little difference. Or use BenchmarkPlot.

tr = Transpose[{#, #}] &;
trEval = Evaluate[Transpose[{#, #}] &];
r = Range[10^7];

Needs["GeneralUtilities`"]
BenchmarkPlot[{tr, trEval}, r[[;; #]] &, 10^Range[7]]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

The time is spent rendering the large output in the notebook. Add ; to suppress the output

(tr = Transpose[{Range[10^5], Range[10^5]}];) // AbsoluteTiming
(* {0.000537, Null} *)

(tr = Evaluate[Transpose[{Range[10^5], Range[10^5]}]];) // AbsoluteTiming
(* {0.000352, Null} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract