For things like this, I use a little code timer that I wrote. It uses Timer0 to measure execution time of code snippets.
Presently, it is designed for use with an 18F8720 running at 20Mhz, but it could be easily modified for other processors or speeds.
'------------------------------------------------------------------------
DEFINE OSC 20 ' Set for 20Mhz operation
DEFINE NO_CLRWDT 1 ' Don't waste cycles clearing WDT
DEFINE _18F8720 1
DEFINE HSER_RCSTA 90H
DEFINE HSER_TXSTA 20H
DEFINE HSER_CLROERR 1
DEFINE LOADER_USED 1
Define USE_LFSR 1
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 50
DEFINE I2C_HOLD 1
DEFINE I2C_SLOW 1
TRISC = %10111111 ' Hardware serial port on PORTC.7,PORTC.6
PSPCON = %00000000 ' No PSP
MEMCON = %10000000 ' No External Memory
CMCON = %00000111
' No Comparator used, turn it off
TXSTA1.2 = 1
SPBRG = 129
INTCON = $80 ' Turn off interrupts
T0CON = %10001000 ' No Prescaler,16 bit Timer 0
TimerValue VAR WORD
RealTime VAR WORD
OverFlow VAR BYTE
Prescale VAR BYTE
DummyVal VAR Byte
'-------------------------------------------------------------------------------
' Put Variables required by program here
'-------------------------------------------------------------------------------
Restart:
'-------------------------------------------------------------------------------
'Put code to be timed here
'----------------------------------------------------------------------------
Time_It:
TimerValue.LowByte = TMR0L
TimerValue.Highbyte = TMR0H
IF INTCON.2 = 1 THEN
INTCON.2 = 0
OverFlow = OverFlow + 1
If OverFlow = 1 THEN
T0CON = %10000010
Prescale = 8
ENDIF
IF OverFlow = 2 THEN
HSEROUT ["Execution time too long - choose another prescaler value",13,10]
ENDIF
GOTO RESTART
ENDIF
HSEROUT ["Execution Time = ",#(TimerValue * Prescale), " Cycles, ",#((TimerValue/5)*Prescale)," Microseconds",13,10,10]
HSEROUT ["Press any key to restart",13,10]
HSERIN [DummyVal]
GOTO Restart
END
Bookmarks