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

Online Help

All Products    Maple    MapleSim


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

Calling Sequence

CodeTools[Usage](expression, options)

CodeTools[CPUTime](expression, options)

CodeTools[RealTime](expression, options)

CodeTools[GCTime](expression, options)

Parameters

expression

-

expression

options

-

optional arguments of the form keyword=value; keyword can be one of output, iterations, and quiet

Description

• 

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.

Examples

withCodeTools:

Usageifactor32!+1

memory used=10.07MiB, alloc change=35.01MiB, cpu time=89.00ms, real time=90.00ms, gc time=4.71ms

6114608365293128894190494740737772281

(1)

Usageifactor33!+1,output=bytesused

memory used=15.60MiB, alloc change=38.00MiB, cpu time=216.00ms, real time=162.00ms, gc time=112.95ms

16354208

(2)

Usageifactor36!+1,output=all

Recordrealtime=0.069,cputime=0.069,gctime=0.,gcrealtime=0.,bytesused=6621856,bytesalloc=0,output=37837391483165202043669043459524628666916941

(3)

dataUsageifactor39!+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

dataRecordrealtime=0.598,cputime=0.630,gctime=0.0776510000,gcrealtime=0.04263496399,bytesused=42203584,bytesalloc=−4198400,output=795755448536314610264891493930705821478100704367

(4)

databytesused

42203584

(5)

Usageifactor40!+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

(6)

Usageifactor42!+1,output=cputime,bytesused,quiet

1.084,79818560

(7)

The following takes too little resources to give useful information. Increasing the number of iterations improves this.

Usageifactor15!+1

memory used=4.58KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

5947946271341

(8)

Usageifactor15!+1,iterations=106

memory used=48 bytes, alloc change=0 bytes, cpu time=8.4e+02ns, real time=8.4e+02ns, gc time=0ns

5947946271341

(9)

infolevelUsage5:

Usageifactor15!+1,iterations=2Units

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

5947946271341

(10)

unassigninfolevelUsage

withLinearAlgebra:

UsageLUDecompositionRandomMatrix25,output=all

UsageLUDecompositionRandomMatrix35,output=cputime,output

memory used=8.46MiB, alloc change=0 bytes, cpu time=150.00ms, real time=112.00ms, gc time=82.44ms

UsageLUDecompositionRandomMatrix45,output=cputime,output,bytesused

memory used=20.15MiB, alloc change=0 bytes, cpu time=96.00ms, real time=96.00ms, gc time=0ns

CPUTimeifactor45!+1

2.019,2931978954403404920630438210640397406279590400959696408493

(11)

RealTimeifactor46!+1

3.394,47268662306503771535067435777793891607546778854755077304349

(12)

GCTimeifactor45!+1

0.558819000,2931978954403404920630438210640397406279590400959696408493

(13)

GCTimeifactor46!+1,real=true

0.360509395,47268662306503771535067435777793891607546778854755077304349

(14)

Compatibility

• 

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