What's the proper way to get Timing
and post-process it for example to convert to a TimeObject
as a defined function?
In line, this replacement works as intended:
Inverse[Table[RandomReal[], {3000}, {3000}]]; // Timing //
Replace[{timeSec_, value_} :> {TimeObject[{0, 0, timeSec}], value}]
gives (full form):
List[TimeObject[List[0,0,3.450302`],"Instant",None],Null]
but when trying to define a function to perform both the timing and conversion, the actual timing extracted is not that of the intended input expression:
unitTiming[expr_] := Timing[expr] // Replace[{timeSec_,value_}:> {TimeObject[{0,0,timeSec}],value}]
Testing on the matrix inversion above:
Inverse[Table[RandomReal[], {3000}, {3000}]]; // unitTiming
gives:
List[TimeObject[List[0,0,0.000011`],"Instant",None],Null]
I've tried several variations on the definition (eg using RightComposition
) but can't get the desired results.
TimeObject
refer to an instant in time? It doesn't seem to make sense to convert a duration to aTimeObject
. $\endgroup$TimeObject
auto-converts to minutes if > 60sec (ditto hours), whereas I'd have to manually tune the logic. In any case, usingQuantity
has the same problem. $\endgroup$SetAttributes[unitTiming, HoldAll]
$\endgroup$Timing[expr]
to already be evaluated on the input, prior to theReplace
? $\endgroup$Timing
andAbsoluteTiming
for the same input? $\endgroup$