# Show timing of every output

I know I can follow Wolfram's guide and enable "ShowTiming" to show the timing of the previous command at the bottom of the window.

Additionally, I can enable "AddTimeStamp" to show when each cell is evaluated next to the cell. I was wondering if I could sorta combine "ShowTiming" and "AddTimeStamp" and show how long each output takes NEXT to the output cell (replacing the timestamp). So instead of the output cells showing the timestamp, it would instead show the timing.

I know I could calculate this myself by subtracting the output date from the input date, but it would be more convenient to have this happen automatically.

• What do you want to have happen when there is no output cell to attach the timing to? – Carl Woll Jul 9 '19 at 22:34
• Would you give me an example? Like if I suppress the output with ;? – Max Coplan Jul 10 '19 at 15:47

Here's a Mathematica 12 stylesheet solution that adds the "ShowTiming" status area to each output cell label:

CurrentValue[EvaluationNotebook[], EvaluationCompletionAction] = {"ShowTiming"};

SetOptions[
EvaluationNotebook[],
StyleDefinitions->Notebook[
{
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEpilog :> With[{time = AbsoluteCurrentValue["WindowStatusArea"]},
If[CurrentValue[NextCell[], CellStyle] === {"Output"},
SetOptions[NextCell[], CellLabel -> time<>" Out["<>ToString[\$Line-1]<>"]="]
]
]
]
},
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]

• I was confused why it didn't work and now I know, one needs to have EvaluationCompletionAction set to "ShowTiming". p.s. even then it can't handle multi output cells from single input. (Don't want to be picky, just giving a feedback.) – Kuba Jul 10 '19 at 7:19
• @Kuba Thanks for mentioning the EvaluationCompletionAction issue! Yes, multiple outputs are an issue. – Carl Woll Jul 10 '19 at 14:47
• This isn't working for me. Which I think has something to do with this. I get a StringJoin::string error saying StringJoin: String expected at position 1 in Automatic <> Out[1]=. – Max Coplan Jul 16 '19 at 15:16
• @MaxCoplan It seems that obtaining the value of the window status area is an M12 feature. – Carl Woll Jul 16 '19 at 15:34
• Well, it seems I'll have to wait until that's resolved to get the benefits of it. I was able to confirm that your solution works though, using the window-resizing trick. So I can go ahead and mark that as right – Max Coplan Jul 16 '19 at 19:17