Hello everyone! I couldnt find a thread on if anyone has done this before, so I ran my own tests to see how quickly GCB/PIC can run through very large numbers (words and longs). I had initially started with random numbers to make sure I didnt fudge the test results, but came to the conclusion quickly that in doing so, I might get very large results, larger than what a PIC can handle. So in the end, I used semi-realistic numbers that I know would work.
The reason why I chose to do this test is because I want to make an electronic lead screw for my lathe, so I want to make sure it can do the math in enough time and send a pulse out to move a stepper while the main spindle is running. I wanted to make sure a 8 Bit micro can do it in enough time, or else I would have to learn 32 Bit Micro's and find a comparible language to GCB.
Complier:
0.98.07 RC20 2020-07-14 (Windows 64 bit)
PIC: 18F25K20
16384 Words of Program Memory
1536 Bytes of Ram
I tested it through 4 main speeds, 8, 16,32 and 64 Mhz. By time I got to the multplication tests, that was when I realized its better off just testing at 64Mhz, since if you are doing something quick, you will most likely use that speed.
When I selected numbers, I made sure I got the correct result by having it be spit out via UART. I then commented the UART lines back in and just observed a port going High/Low. Since it was toggling, both speeds are roughly the same.
End result: Worst case test was division that took 69uS @64 Mhz. It seems that trying to keep things as words is most efficient, unless you need the large numbers that long's can give.
Note: I never tested Integers. Opps.
I cant say for certain if I tested things "correctly" but this will give a ball park figure. Maybe I can improve my testing method as its possible I did something incorrect.
Hi Chris,
a division by a constant value often can be rewritten to a constant multiplication like (2^16 / divisor), followed by a right shift (or taking the high word as result).
So instead of Word Test
Alpha=65530; Beta=3; result = Alpha / Beta
write
Alpha=65530; Beta=65536/3; result = (Alpha * Beta) shr 16
A multiplication is many times faster than a division,
especially if the processor has a hardware multiplicator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone! I couldnt find a thread on if anyone has done this before, so I ran my own tests to see how quickly GCB/PIC can run through very large numbers (words and longs). I had initially started with random numbers to make sure I didnt fudge the test results, but came to the conclusion quickly that in doing so, I might get very large results, larger than what a PIC can handle. So in the end, I used semi-realistic numbers that I know would work.
The reason why I chose to do this test is because I want to make an electronic lead screw for my lathe, so I want to make sure it can do the math in enough time and send a pulse out to move a stepper while the main spindle is running. I wanted to make sure a 8 Bit micro can do it in enough time, or else I would have to learn 32 Bit Micro's and find a comparible language to GCB.
Complier:
0.98.07 RC20 2020-07-14 (Windows 64 bit)
PIC: 18F25K20
16384 Words of Program Memory
1536 Bytes of Ram
I tested it through 4 main speeds, 8, 16,32 and 64 Mhz. By time I got to the multplication tests, that was when I realized its better off just testing at 64Mhz, since if you are doing something quick, you will most likely use that speed.
When I selected numbers, I made sure I got the correct result by having it be spit out via UART. I then commented the UART lines back in and just observed a port going High/Low. Since it was toggling, both speeds are roughly the same.
End result: Worst case test was division that took 69uS @64 Mhz. It seems that trying to keep things as words is most efficient, unless you need the large numbers that long's can give.
Note: I never tested Integers. Opps.
I cant say for certain if I tested things "correctly" but this will give a ball park figure. Maybe I can improve my testing method as its possible I did something incorrect.
Results below:
Hi Chris,
a division by a constant value often can be rewritten to a constant multiplication like (2^16 / divisor), followed by a right shift (or taking the high word as result).
So instead of Word Test
Alpha=65530; Beta=3; result = Alpha / Beta
write
Alpha=65530; Beta=65536/3; result = (Alpha * Beta) shr 16
A multiplication is many times faster than a division,
especially if the processor has a hardware multiplicator.