Timing in Spin
CassLan
Posts: 586
Hi all,
This may seem like a dumb question...that hasn't stopped me before [noparse]:)[/noparse]
Anyway, I'm working on PrEditor, I'm trying to speed it up, I have a routine that takes place with every keystroke, and its just not snappy enough yet
In order to experiment a bit to make it faster I need to know exactly how long its taking.
I've put in the following code:
Then I display these three long sized variables via Parallax Serial Terminal
I'm thinking the only time this could be incorrect is if the cnt rolls over while the routine is happening...which is why I'm outputting all 3 to the terminal
Currently I have a value of 9,213,008 for the difference between StartCNT and StopCNT
These are clock cycles right?
And since this is happening inside of 1 of 8 cogs, each of these happens at 10Mhz? (5Mhx xtal at x16 PLL)
So thats 921.3 milliseconds?
I know for serious timing stuff PASM should be used, I'm just trying to get a handle on how to clock routines in spin to make sure my improvements are really improvements [noparse];)[/noparse]
Thanks,
Rick
Post Edited (CassLan) : 6/20/2009 8:22:34 PM GMT
This may seem like a dumb question...that hasn't stopped me before [noparse]:)[/noparse]
Anyway, I'm working on PrEditor, I'm trying to speed it up, I have a routine that takes place with every keystroke, and its just not snappy enough yet
In order to experiment a bit to make it faster I need to know exactly how long its taking.
I've put in the following code:
'' This is the first line of the routine StartCNT := cnt ''This is the last line of the routine StopCNT := cnt DiffCNT := StartCNT - StopCNT
Then I display these three long sized variables via Parallax Serial Terminal
I'm thinking the only time this could be incorrect is if the cnt rolls over while the routine is happening...which is why I'm outputting all 3 to the terminal
Currently I have a value of 9,213,008 for the difference between StartCNT and StopCNT
These are clock cycles right?
And since this is happening inside of 1 of 8 cogs, each of these happens at 10Mhz? (5Mhx xtal at x16 PLL)
So thats 921.3 milliseconds?
I know for serious timing stuff PASM should be used, I'm just trying to get a handle on how to clock routines in spin to make sure my improvements are really improvements [noparse];)[/noparse]
Thanks,
Rick
Post Edited (CassLan) : 6/20/2009 8:22:34 PM GMT
Comments
You only need to display the difference StopCNT-StartCNT. For time delays less than around 25 seconds, this will be a correct positive time interval.
If you want a display in microseconds, display (StopCnt-StartCnt) / (CLKFREQ/1000000).
If you want a display in milliseconds, display (StopCnt-StartCnt) / (CLKFREQ/1000)
To make the result more accurate you can calculate the diff of the two clock-measurements without code in between. This is the offset you can subtract from the diff of your code.
Post Edited (MagIO2) : 6/20/2009 9:05:44 PM GMT
Yes Its Stop-Start, I had it correct in the program but wrote it incorrectly when posting.
I understand the total system is running at 80Mhz, I thought that each cog runs independently at 1/8th of that speed
Is this faulty thinking?
PS - So far I've got it down by 35%! make that 44%! That multiplication is a killer.
Rick
Most instructions need 4 clock-cycles. So the instruction throughput is 1/4th of the system clock which makes 20MIPS per COG.
Multiplication is bad if you don't have hardware multipy. Remember that multiplication by power of 2 operands (2,4,8,16...) can be done by shifting.
Post Edited (MagIO2) : 6/20/2009 10:40:27 PM GMT
Rick