limits the amount of CPU time spent on a computation - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Procedures and Functions : Time and Space : timelimit

timelimit - limits the amount of CPU time spent on a computation

Calling Sequence

timelimit(t, x)




time limit in seconds






The timelimit function evaluates the expression x, but gives up if the evaluation takes longer than the number of seconds specified by t.


Note: For efficiency reasons, the timelimit bound is ignored while in built-in routines.


If the expression is successfully evaluated within the specified time, timelimit returns the value of the expression. If the time limit is reached before the expression is evaluated, timelimit generates the error `time expired`.


The `time expired` error may be caught by a try...catch construct, so long as the try...catch is at a higher level than the call to timelimit. Lower level try...catch constructs (that is, those executed by the expression that is being time-limited) will not catch `time expired`, since to do so would make it impossible to time-limit something which catches exceptions.


The time limit can be specified to the nearest 1/100th of a second, although the actual time allowed can vary by more than that, depending on the underlying architecture, and the Maple operation taking place at the time that the limit expires.


Nested calls to timelimit are allowed, however all time limits are considered to be in effect.  Thus an inner call to timelimit will not override the time limit set by an outer call.  In addition the `time expired` exception can only be caught outside of the call to timelimit which imposed the limit that expired.


If a nested call to timelimit sets the same limit as an outer call, the outer limit will be treated as the expiring limit.


The timelimit function cannot be used to limit the time of computations within evalhf.


If timelimit is called with a limit of -1, the operation will never time out.  Calling timelimit with any other values less than zero will result in an error.


The maximum specifiable time limit is somewhat session dependent, but is usually around 2^24 seconds.  To specify a higher time limit value, -1 should be used.

Thread Safety


The timelimit command is thread-safe as of Maple 15.


For more information on thread safety, see index/threadsafe.


f := proc()
    global i;
    for i to 200000 do
    end do
end proc:


Error, (in f) time expired




See Also

debugger, time, try

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam