TIMEIT

From Jacket Wiki

Jump to: navigation, search
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.
    

GFOR Supported

Yes

GCOMPILE Supported

No

Types Supported

-  GDOUBLE   GSINGLE   GLOGICAL   GINT32   GINT8   GUINT32   GUINT8   COMPLEX 

Types Not Supported

-

More Details
  • You can either feed built-in functions (e.g. min, max) or your own functions (e.g foo) [see the Notes].
  • The input is a function handle. The examples above use anonymous function handles.
  • Timeit works both on CPU or GPU code.
  • It accounts for any necessary warmup time.

Notes

  • 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

Double-Precision GPU: 0.0028

See Also

GSYNC, GEVAL, TIC, TOC

Views