Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Expressions > Evaluation Control >

TimeConstrained

TimeConstrained[expr, t]
evaluates expr, stopping after t seconds.
TimeConstrained[expr, t, failexpr]
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 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 Mathematica kernel process; it does not include additional threads or processes.
Terminate a computation if it takes more than 1 second:
Terminate a computation if it takes more than 2 seconds:
With the default method, it gets a (not quite as accurate) solution within the time constraint:
Terminate a computation if it takes more than 1 second:
In[1]:=
Click for copyable input
Out[1]=
 
Terminate a computation if it takes more than 2 seconds:
In[1]:=
Click for copyable input
Out[1]=
With the default method, it gets a (not quite as accurate) solution within the time constraint:
In[2]:=
Click for copyable input
Out[2]=
New in 1 | Last modified in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team