CodeTools
Usage
measure time and memory usage information for executing an expression
CPUTime
measure CPU time used to execute an expression
RealTime
measure real time used to execute an expression
GCTime
measure real time used performing garbage collection
Calling Sequence
Parameters
Description
Examples
Compatibility
CodeTools[Usage](expression, options)
CodeTools[CPUTime](expression, options)
CodeTools[RealTime](expression, options)
CodeTools[GCTime](expression, options)
expression
-
options
optional arguments of the form keyword=value; keyword can be one of output, iterations, and quiet
The Usage command records time and memory usage statistics for the evaluation of expression.
By default, usage statistics are printed and the result of the evaluation of expression is returned.
The option output=value can be given to return one of the statistics where value is one of realtime, cputime, gctime, gcrealtime, bytesused, bytesalloc, or output or, to specify multiple outputs, a list of any of these. Multiple outputs are returned in the order they are specified. If the output from evaluating expression is an expression sequence, it will be returned as a list if it appears in the middle of the outputs.
output may also be all to return a record containing all the statistics. In this case, the statistics are not printed by default. Memory is returned in bytes (with IEC binary prefixes) and time is returned in seconds.
You can specify an option of the form iterations = posint. This will cause expression to be evaluated the specified number of times, and all results other than bytesalloc to be divided by that same number (bytesalloc is returned unchanged). The default number of iterations is 1.
Alternatively, you can specify the option as iterations = t, where t is an amount of time expressed using the Units package. In this case, the Usage command will estimate the number of iterations that takes the given amount of real time. Estimating this number takes some time itself; if this estimation process takes close to the amount of time requested, no subsequent run is made anymore. More information about this estimation process can be obtained by setting the infolevel of CodeTools or Usage.
The option quiet=truefalse can be given to suppress printing of the statistics (or to force printing when output=all).
CPUTime(expression) calls Usage(expression, output=[cputime,output], quiet). It can be passed an option of the form iterations = posint, which is also passed to Usage.
RealTime(expression) calls Usage(expression, output=[realtime,output], quiet). It can be passed an option of the form iterations = posint, which is also passed to Usage.
GCTime(expression,real=truefalse) calls Usage(expression, output=[gcrealtime,output], quiet) if the second argument is true or Usage(expression, output=[gctime,output], quiet) if the second argument is false (the default). It can be passed an option of the form iterations = posint, which is also passed to Usage.
with⁡CodeTools:
Usage⁡ifactor⁡32!+1
memory used=10.07MiB, alloc change=35.01MiB, cpu time=89.00ms, real time=90.00ms, gc time=4.71ms
61146083⁢652931⁢2889419049474073777⁢2281
Usage⁡ifactor⁡33!+1,output=bytesused
memory used=15.60MiB, alloc change=38.00MiB, cpu time=216.00ms, real time=162.00ms, gc time=112.95ms
16354208
Usage⁡ifactor⁡36!+1,output=all
Record⁡realtime=0.069,cputime=0.069,gctime=0.,gcrealtime=0.,bytesused=6621856,bytesalloc=0,output=37⁢83⁢739⁢1483⁢165202043⁢669043459524628666916941
data≔Usage⁡ifactor⁡39!+1,output=all,quiet=false
memory used=40.25MiB, alloc change=-4.00MiB, cpu time=630.00ms, real time=598.00ms, gc time=77.65ms
data≔Record⁡realtime=0.598,cputime=0.630,gctime=0.0776510000,gcrealtime=0.04263496399,bytesused=42203584,bytesalloc=−4198400,output=79⁢57554485363⁢146102648914939⁢30705821478100704367
databytesused
42203584
Usage⁡ifactor⁡40!+1,output=cputime,bytesused
memory used=4.06MiB, alloc change=0 bytes, cpu time=62.00ms, real time=63.00ms, gc time=0ns
0.062,4260352
Usage⁡ifactor⁡42!+1,output=cputime,bytesused,quiet
1.084,79818560
The following takes too little resources to give useful information. Increasing the number of iterations improves this.
Usage⁡ifactor⁡15!+1
memory used=4.58KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns
59⁢479⁢46271341
Usage⁡ifactor⁡15!+1,iterations=106
memory used=48 bytes, alloc change=0 bytes, cpu time=8.4e+02ns, real time=8.4e+02ns, gc time=0ns
infolevelUsage≔5:
Usage⁡ifactor⁡15!+1,iterations=2⁢Unit⁡s
Usage: "trying out" 1 "iteration" Usage: "trying out" 2 "iterations" Usage: "trying out" 4 "iterations" Usage: "trying out" 8 "iterations" Usage: "trying out" 16 "iterations" Usage: "trying out" 32 "iterations" Usage: "trying out" 64 "iterations" Usage: "trying out" 128 "iterations" Usage: "trying out" 256 "iterations" Usage: "trying out" 512 "iterations" Usage: "trying out" 1024 "iterations" Usage: "trying out" 2048 "iterations" Usage: "trying out" 4096 "iterations" Usage: "trying out" 8192 "iterations" Usage: "trying out" 16384 "iterations" Usage: "trying out" 32768 "iterations" Usage: "trying out" 65536 "iterations" Usage: "trying out" 131072 "iterations" Usage: "setting iterations to" 1464491 memory used=48 bytes, alloc change=0 bytes, cpu time=8.5e+02ns, real time=8.5e+02ns, gc time=0ns
unassign⁡infolevelUsage
with⁡LinearAlgebra:
Usage⁡LUDecomposition⁡RandomMatrix⁡25,output=all
Usage⁡LUDecomposition⁡RandomMatrix⁡35,output=cputime,output
memory used=8.46MiB, alloc change=0 bytes, cpu time=150.00ms, real time=112.00ms, gc time=82.44ms
Usage⁡LUDecomposition⁡RandomMatrix⁡45,output=cputime,output,bytesused
memory used=20.15MiB, alloc change=0 bytes, cpu time=96.00ms, real time=96.00ms, gc time=0ns
CPUTime⁡ifactor⁡45!+1
2.019,293⁢19789544034049⁢20630438210640397406279590400959696408493
RealTime⁡ifactor⁡46!+1
3.394,47⁢268662306503771535067⁢435777793891607546778854755077304349
GCTime⁡ifactor⁡45!+1
0.558819000,293⁢19789544034049⁢20630438210640397406279590400959696408493
GCTime⁡ifactor⁡46!+1,real=true
0.360509395,47⁢268662306503771535067⁢435777793891607546778854755077304349
The iterations option was introduced in Maple 15.
For more information on Maple 15 changes, see Updates in Maple 15.
The iterations option was updated in Maple 16.
The output option was updated in Maple 18.
The CodeTools[Usage] command was updated in Maple 2017.
The GCTime option was updated in Maple 2017.
See Also
kernelopts
time
Download Help Document