6

I have a computation which is taking very long

AbsoluteTiming[sr = ShellRegion@region];

Instead of getting $Aborted, is there a system method to get a time estimate of how long it was running before being aborted?

M.R.
  • 31,425
  • 8
  • 90
  • 281

2 Answers2

8

Maybe the following construct suits your need, take for example

Module[{tic},
tic = SessionTime[];
CheckAbort[
Do[Print[n]; Pause[1], {n, 10}] (* here goes your expression *), 
SessionTime[] - tic
]

or wrapped in a convenient function

SetAttributes[try, HoldFirst]
try[expr_] := Module[{tic},
tic = SessionTime[];
CheckAbort[expr, SessionTime[] - tic]
]

that can be called with some expression you wish to evaluate

try[Do[Pause[1]; Print[n], {n, 10}]]

animated gif

Sascha
  • 8,459
  • 2
  • 32
  • 66
6

Simply wrapping your computation in CheckAbort as suggested by @Sascha seems to be sufficient to achieve most of what you want. E.g.

AbsoluteTiming[CheckAbort[Pause[20], Null]]
mikado
  • 16,741
  • 2
  • 20
  • 54