guillermo
(JOSÉ GUILLERMO SÁNCHEZ LEÓN)
June 30, 2021, 3:54pm
1
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} *)
mikebesso
(Mike Besso)
June 30, 2021, 8:26pm
3
@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]]
mikebesso
(Mike Besso)
July 1, 2021, 1:10pm
5
Rohit:
Thanks. I can trust the space-time continuum again.