This is not immediately an answer to OP's question but it does provide an initialization code which one can use in all her/his files so that they do not have to worry about forgetting inserting
One can simply define a new variable, say duration, and record the evaluation of each calculation to this variable in the background.
Following code is sufficient for that:
$PreRead := ((durationTemp = AbsoluteTime); Function[#]);
$Post := ((duration[$Line] = AbsoluteTime - durationTemp);Function[#]);
What it does is to record the absolute time when the input is given and calculate the time passed when the evaluation finishes. This is done for each calculation, and recorded with input line so that
duration[n] gives the time spent for the calculation of
As an example:
This is the most basic form; but one can modify
duration function so that it counts in minutes instead of seconds, and it may garbage collect itself (say only keeps last 30 entries).
One can actually easily implement last idea using
Associations. Specifically, below code does the same job using associations, and also only keeps last $n$ entries, where $n$ is set by
duration = <||>;
durationLength = 3;
$PreRead := (durationTemp = AbsoluteTime; Function[#]);
$Post := (If[KeyExistsQ[duration, $Line - durationLength],
KeyDropFrom[duration, $Line - durationLength];
AssociateTo[duration, $Line -> AbsoluteTime - durationTemp],
AssociateTo[duration, $Line -> AbsoluteTime - durationTemp]];
As an example:
Depending on the conditions, it may actually be a better idea to dedicate a stream to this and let it record the times to a file in the background. For example, one can use
OpenWrite to create a temporary file per session, but I cannot imagine any scenario for which writing to a file is better than having this variable if the file is to be cleared after session ends (assuming session times are not extremely long). However, if one wants to keep a long record, then dedicating a file for this data and using
OpenAppend to add these information to the same file may be useful. For example, if one has a 6 month long project and expects to have thousands of evaluation whose timing information happens to be useful data, then this may be relevant.