LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Fuction Times

Is there any way to measure how long a function is taking to execute?
I have a one second tick calling a largish function, I am trying to optimise the function to run faster as I do not want to get anywhere near to over running the tick. Hence I would like to know how long the function takes to execute.

Thanks James
0 Kudos
Message 1 of 4
(3,189 Views)
Use Timer() (utility library) before and after the function and calculate
the difference.

Regards,Manfred

James@Motorola schrieb in im Newsbeitrag:
506500000008000000F71D0000-986697009000@quiq.com...
> Is there any way to measure how long a function is taking to execute?
> I have a one second tick calling a largish function, I am trying to
> optimise the function to run faster as I do not want to get anywhere
> near to over running the tick. Hence I would like to know how long the
> function takes to execute.
>
> Thanks James
0 Kudos
Message 2 of 4
(3,189 Views)
I usually use this method to monitor a timer callback:

int CVICALLBACK timerCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double tn;

if (event != EVENT_TIMER_TICK) return 0;

tn = *(double *)eventData2; // Time from last execution of interrupt

// I use a secondary panel to display monitoring values. monH is the handle to that panel
if (monH) {
SetCtrlVal (monH, mon_life, *(double *)eventData1); // Total time of execution of the program
SetCtrlVal (monH, mon_scan, tn * 1000.0); // Display time from last execution (msecs)
}

//
// Here I put the function code to monitor...
//

// Here I display the time of execution of the function
if (monH) {
SetCtrlVal (monH, mon_timer, (Timer() - *(double *)eventDat
a1) * 1000.0);
}

return 0;
}

To speed up the time of execution of timer interrupts I usually put all panels updates and/or file I/O in external functions called by PostDeferredCall. This permit me to monitor error conditions and display messageboxes to inform the operator without disturbing the interrupt flow ans scanning.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 4
(3,189 Views)
Hi,

in case the delta-t to measure is less than the timer resolution (1 millisecond) I use an external oscilloscope (standard or storage) and connect it to an LPT port (e.g. probe to pin 2 = lowest of the 8 out bits, pin 25 = ground).

Step 1:

Program a shortest possible puls:
outp(lpt_address, 1); // pulse to HI
outp(lpt_address, 0); // pulse to LO
Delay(0.001); // 1 millisec Delay
and measure the pulse width in a repetitive loop. My resulting puls widths found on a Pentium II / 350 MHz were:
- under MS-DOS: 1.3 microsecs
- under Win 98: 1.5 "
- under Win NT: 17 "
- under W2000: 24 "

Step 2:

Embed your function to measure between the "switch to HI" and "switch to LO" command of the pulse and meas
ure the pulse width on the oscilloscope, it gives you the duration of your function.

For more details see the attached C-Source (running equally under Turbo-C (MS-DOS) and CVI :-))))

Heinz Hoeffken
0 Kudos
Message 4 of 4
(3,189 Views)