Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
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: 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.
Examples
f := proc() global i; for i to 200000 do 2^i end do end proc:
Error, (in f) time expired
See Also
debugger, time, try
Download Help Document