# Evaluation time for each evaluated cell (as a whole)

I have a Mathematica notebook that has a number of cells, and each cell has a number of code lines. Sometimes it takes long hours to finish evaluating each cell and I want to compare their evaluation times. I would like to know how much each cell has taken (wall-clock time) in terms of evaluation and would like to have that as output printed after each cell evaluates, and before the kernel moves on to next cell.

Is there a simple way to do this? For example, something like a stopwatch ON and OFF commands that I can wrap around the code written inside each cell?

Note that the option to ShowTiming in Options Inspector is not helpful to me here, as it shows the timing for the last cell, but not each. When I run a Notebook and it takes long time, say 2 days, it would be nice to see how long each cell took on its own.

• You may wrap Timing around each cell. Oct 10, 2021 at 9:26

In the OptionInspector, you can set EvaluationCompletionAction to "AddTimeStamp". This prepends the Date and Time to all In and Out cell labels. This is almost what you want, but requires some post-processing - subtracting the innie from the outie to get the elapsed time. This can probably be automated.

Here's a stylesheet based option:

SetOptions[
EvaluationNotebook[],
StyleDefinitions -> Notebook[
{
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[
StyleData["Input"],
CellProlog :> (in=AbsoluteTime[]),
CellEpilog :> (
CurrentValue[EvaluationCell[],CellFrameLabels] =
{
{None, Cell @ BoxData @ StyleBox[
RowBox[{"(",ToBoxes[NumberForm[AbsoluteTime[]-in, {Infinity, 1}]], ")"}],
Plain]
},
{None,None}
}
)
]
},
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]


Example (as a screenshot):

Notice the time in parentheses on the right hand side.

• This does not work on Cells with the style "Code". Can that be fixed? Oct 24, 2021 at 0:30