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?

  • $\begingroup$ Do you mean you leave it running, press Alt+., and then you want to see how long there in between the abort keystokes and when the evaluation queue is free again? $\endgroup$
    – ktm
    Aug 21 '16 at 1:59
  • $\begingroup$ I think so yes, or until it freezes and I kill it $\endgroup$
    – M.R.
    Aug 21 '16 at 2:04
  • $\begingroup$ Out of curiosity, what is region? $\endgroup$
    – Chip Hurst
    Sep 12 '16 at 19:14

Maybe the following construct suits your need, take for example

tic = SessionTime[];
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


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]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.