[Swlug] Interesting variations (Neil Greenwood)

Rhys Sage rhys_sage at yahoo.com
Sat May 27 12:35:42 UTC 2023


Out of curiosity, I modified the code and ran it several times with a standard deviation of about 100 microseconds. I did wonder about assigning the counter to the second core but I'm not 100% sure how to do that. 

Average 944.77
Maximum 1076
Minimum 942

That's pretty interesting and changes every time I run the code - even though it goes through a thousand iterations. The usual deviation from the average seems to be on the high side, indicating something within the OS is definitely gobbling random amounts of CPU time. 

Putting it into context, 100 microseconds does not sound much. In this particular instance I'll do a quick calculation.

A .223 bullet travelling at 3200 feet per second will travel well over half an inch (0.64) in that amount of time. 

This has me now wondering whether I can do better in terms of speed and accuracy with an Arduino Nano Every (I have some). I would love to try it on a ATTiny88 but I can't get the blessed things to perform (I have some of those too).

The code used for testing....
#test counter versus counting
import time
Min = 0
Max = 100
Tix = 0
TimTot = 0
MiniTot = 100000000000
MiniMax = 0
TempTot = 0


for y in range(Min,Max):
    tim1 = time.ticks_us()
    for x in range(Min, Max):
      Tix += 1


    tim2 = time.ticks_us()
    TempTot = tim2 - tim1
    TimTot = TimTot + TempTot
    if (TempTot < MiniTot): MiniTot = TempTot
    if (TempTot > MiniMax):  MiniMax = TempTot
    
print("Average", TimTot/100)
print("Maximum",MiniMax)
print("Minimum", MiniTot)



More information about the Swlug mailing list