CodeTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : CodeTools : CodeTools/Usage

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.28MiB, alloc change=35.01MiB, cpu time=168.00ms, real time=352.00ms, gc time=10.48ms

6114608365293128894190494740737772281

(1)

Usageifactor33!+1,output='bytesused'

memory used=7.83MiB, alloc change=0 bytes, cpu time=131.00ms, real time=152.00ms, gc time=0ns

8210488

(2)

Usageifactor36!+1,output='all'

Recordrealtime=0.414,cputime=0.251,gctime=0.1321200000,gcrealtime=0.2031450272,bytesused=6446520,bytesalloc=31453184,output=37837391483165202043669043459524628666916941

(3)

dataUsageifactor39!+1,output='all',quiet=false

memory used=50.30MiB, alloc change=8.00MiB, cpu time=1.02s, real time=1.44s, gc time=285.81ms

dataRecordrealtime=1.439,cputime=1.023,gctime=0.2858120000,gcrealtime=0.4620258808,bytesused=52747408,bytesalloc=8392704,output=795755448536314610264891493930705821478100704367

(4)

databytesused

52747408

(5)

Usageifactor40!+1,output='cputime','bytesused'

memory used=4.35MiB, alloc change=0 bytes, cpu time=73.00ms, real time=73.00ms, gc time=0ns

0.073,4562200

(6)

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

1.549,81251976

(7)

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

Usageifactor15!+1

memory used=6.98KiB, 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=1.10us, real time=1.22us, gc time=0ns

5947946271341

(9)

infolevelUsage5:

Usageifactor15!+1,iterations=2s

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"   1074360
memory used=48 bytes, alloc change=0 bytes, cpu time=9.4e+02ns, real time=9.6e+02ns, gc time=0ns

5947946271341

(10)

unassign'infolevelUsage'

withLinearAlgebra:

UsageLUDecompositionRandomMatrix25,output='all'

(11)

UsageLUDecompositionRandomMatrix35,output='cputime','output'

memory used=8.46MiB, alloc change=0 bytes, cpu time=71.00ms, real time=74.00ms, gc time=0ns

(12)

UsageLUDecompositionRandomMatrix45,output='cputime','output','bytesused'

memory used=20.15MiB, alloc change=0 bytes, cpu time=268.00ms, real time=244.00ms, gc time=103.76ms

(13)

CPUTimeifactor45!+1

2.744,2931978954403404920630438210640397406279590400959696408493

(14)

RealTimeifactor46!+1

5.715,47268662306503771535067435777793891607546778854755077304349

(15)

GCTimeifactor45!+1

0.502984000,2931978954403404920630438210640397406279590400959696408493

(16)

GCTimeifactor46!+1,real=true

0.802694321,47268662306503771535067435777793891607546778854755077304349

(17)

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