Skip to content

Instantly share code, notes, and snippets.

@sethcohn
Created August 9, 2017 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethcohn/8ee563517b95a9a19ce55636a7665bd9 to your computer and use it in GitHub Desktop.
Save sethcohn/8ee563517b95a9a19ce55636a7665bd9 to your computer and use it in GitHub Desktop.
Pixel Time Trials - for testing write speeds in CircuitPython
from board import *
import time
import urandom
import neopixel
pininuse = A0 #change for your board pin
strandsize = 144
stepsize = 10
startingpixel = 5
color = (30,0,0)
trialcount = 5
def timedrun(trials,pixels,color,autow):
# combined will be divided by trial total, set once before the trials
setcombined = 0
writecombined = 0
#set low to high value, so it'll be replaced
setlow = 60
writelow = 60
#set high to low value, so it'll be replaced
sethigh = 0
writehigh = 0
for trial in range (0, trials): # # of trials, take high, low, and average
with neopixel.NeoPixel(pininuse, pixels, 3, 1, autow) as np: # change to match pin and pixel count
#np.auto_write = autow
starttime = time.monotonic()
for i in range(0, pixels):
np[i] = color
writestop = time.monotonic()
np.show()
showstop = time.monotonic()
#collect data on run
settime = writestop - starttime
setcombined += settime
if settime > sethigh:
sethigh = settime
if settime < setlow:
setlow = settime
writetime = showstop - writestop
writecombined += writetime
if writetime > writehigh:
writehigh = writetime
if writetime < writelow:
writelow = writetime
print (trials, color, autow, pixels, setlow, setcombined/trials, sethigh, writelow, writecombined/trials, writehigh)
def pixeltimetrials():
print ("trials", "color", "autowrite", "#pixels", "setlow", "setavg", "sethigh", "writelow", "writeavg", "writehigh")
for size in range(startingpixel, strandsize, stepsize): #144 neopixel strand tested, 10-140
timedrun(trialcount, size, color, True) #auto_write True
timedrun(trialcount, size, color, False) #auto_write False
print ("Trial run complete")
pixeltimetrials()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment