TIMEIT
From Jacket Wiki
Back to Function List
Time the execution of a built-in or user-defined function.
Usage
| Jacket for M Language | |||||||||||
| Supported Syntax | |||||||||||
>> fn = @() grand(512); % function handle with no inputs; output ignored >> seconds = timeit(fn) seconds = 5.2905e-04 % timings are reproducible up to tic/toc precision >> a = rand(4096,'single'); >> timeit(@() imrotate(a,180)) % time 180 degree image rotation ans = 0.0491 >> a = gsingle(a); >> timeit(@() imrotate(a,180)) ans = 0.0052 >> timeit(@imrotate, a, 180); % equivalent to above calling format >> timeit(@my_function, 'all') % when my_function uses multiple gpus. |
|||||||||||
|
|||||||||||
Notes
- A good blog post on using TIMEIT: "A better way to time Jacket code".
- Here's how you time a user-defined function. As an example, we wish to time timeMultiply, which generates two matrices and multiplies them.
function timeMultiply(type) % the inputs are either CPU or GPU % based on the value of 'type' A = rand(512,type); B = rand(512,type); C = A*B; end
To time the CPU version of timeMultiply, simply feed it the string 'single' or 'double'.
>> timeit(@() timeMultiply('single')) >> timeit(@() timeMultiply('double'))
To time the GPU version of timeMultiply We feed the class-name to timeMultiply, not a string, in order to generate GPU variables.
>> timeit(@() timeMultiply(gsingle)) >> timeit(@() timeMultiply(gdouble))
The timing values, for interest:
Single-Precision: 0.0217
Double-Precision: 0.0293
Single-Precision GPU: 0.0017