Wolfram Language & System 10.3 (2015)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)


evaluates expr, stopping after t seconds.

returns failexpr if the time constraint is not met.


  • TimeConstrained generates an interrupt to abort the evaluation of expr if the evaluation is not completed within the specified time.
  • TimeConstrained evaluates failexpr only if the evaluation is aborted.
  • TimeConstrained returns $Aborted if the evaluation is aborted and no failexpr is specified.
  • TimeConstrained is accurate only down to a granularity of at least $TimeUnit seconds.
  • Aborts generated by TimeConstrained are treated just like those generated by Abort, and can thus be overruled by AbortProtect.
  • TimeConstrained[expr,Infinity] imposes no time constraint.
  • TimeConstrained may give different results on different occasions within a single session, for example as a result of different conditions of internal system caches.
  • TimeConstrained takes account only of CPU time spent inside the main Wolfram Language kernel process; it does not include additional threads or processes.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Terminate a computation if it takes more than 1 second:

Click for copyable input

Terminate a computation if it takes more than 2 seconds:

Click for copyable input

With the default method, it gets a (not quite as accurate) solution within the time constraint:

Click for copyable input
Introduced in 1988
| Updated in 2007