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

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} *)

@Rohit:

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

THANKS

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]]

Rohit:

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