timelimit - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

timelimit

limits the amount of CPU time spent on a computation

 Calling Sequence timelimit(t, x)

Parameters

 t - time limit in seconds x - expression

Description

 • The timelimit function evaluates the expression x, but gives up if the evaluation takes longer than the number of seconds specified by t.
 Note: In some cases, the execution may not abort at exactly the time limit imposed, but will abort as soon as it can do so safely.  This can happen when execution is in critical sections of certain 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.

Examples

 > f := proc()     global i;     for i to 200000 do         2^i     end do end proc:
 > $\mathrm{timelimit}\left(0.5,f\left(\right)\right)$
 > $i$
 ${115162}$ (1)

 See Also