SHARE
TWEET

Untitled

a guest Jul 8th, 2019 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import board
  3. from digitalio import DigitalInOut, Direction, Pull
  4. import neopixel
  5. import storage
  6. import sys
  7.  
  8. def write_out(markname, marktime):
  9.     try:
  10.         with open("/benchmarks.csv", "a") as bench:
  11.             bench.write(markname+","+circuitpythonversion+",")
  12.             bench.write('{0:f}\n'.format(marktime))
  13.     except OSError as e:
  14.         pass
  15.     print(markname, circuitpythonversion, marktime, sep=",")
  16.  
  17. #circuit python benchmark
  18. print("running benchmarks")
  19. print(str(sys.implementation[1][0]) + "-" + str(sys.implementation[1][1])+"-"+str(sys.implementation[1][2]))
  20.  
  21. circuitpythonversion = str(sys.implementation[1][0]) + "-" + str(sys.implementation[1][1])+"-"+str(sys.implementation[1][2])
  22.  
  23.  
  24. #Storage
  25. start = time.monotonic()
  26. try:
  27.     with open("/test.txt", "a") as fp:
  28.         for i in range(20):
  29.             fp.write('test')
  30.             fp.flush()
  31.     with open("/benchmarks.csv", "a") as bench:
  32.         bench.write("filesystem benchmark,")
  33.         bench.write(circuitpythonversion)
  34.         bench.write(',{0:f}\n'.format(time.monotonic()-start))
  35. except OSError as e:
  36.     print("write error -- unable to perform filesystem benchmark")
  37.  
  38. #Neopixel
  39. pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.3, auto_write=False)
  40. start = time.monotonic()
  41. for i in range(0,200):
  42.     pixels.fill((255,0,0))
  43.     pixels.show()
  44.     pixels.fill((0,255,0))
  45.     pixels.show()
  46.  
  47. write_out("neopixel flicker", time.monotonic()-start)
  48.  
  49. def rainbow_cycle():
  50.     for x in range(255):
  51.         for y in range(10):
  52.             rc_index = (x * 256 // 10) + y
  53.             pixels[y] = wheel(rc_index & 255)
  54.         pixels.show()
  55.  
  56. def wheel(pos):
  57.     # Input a value 0 to 255 to get a color value.
  58.     # The colours are a transition r - g - b - back to r.
  59.     if pos < 0 or pos > 255:
  60.         return (0, 0, 0)
  61.     if pos < 85:
  62.         return (255 - pos * 3, pos * 3, 0)
  63.     if pos < 170:
  64.         pos -= 85
  65.         return (0, 255 - pos * 3, pos * 3)
  66.     pos -= 170
  67.     return (pos * 3, 0, 255 - pos * 3)
  68.  
  69.  
  70. start = time.monotonic()
  71. for i in range(2):
  72.     rainbow_cycle()
  73.  
  74. write_out("neopixel rainbow", time.monotonic()-start)
  75.  
  76. #GPIO
  77.  
  78. led = DigitalInOut(board.D13)
  79. led.direction = Direction.OUTPUT
  80. start = time.monotonic()
  81. for i in range(0,100000):
  82.     led.value = True
  83.     led.value = False
  84. write_out("GPIO on/off benchmark", time.monotonic()-start)
  85.  
  86.  
  87. out = 0
  88. start = time.monotonic()
  89. for i in range(0,100000):
  90.     out= out+i+i
  91. write_out("integer sum", time.monotonic()-start)
  92.  
  93. out = 0
  94. start = time.monotonic()
  95. for i in range(0,100000):
  96.     out= out + i*i
  97. write_out("integer multi", time.monotonic()-start)
  98.  
  99. out=0.1
  100. start = time.monotonic()
  101. for i in range(0,100000):
  102.     out=out+i+0.1
  103. write_out("float sum", time.monotonic()-start)
  104.  
  105. out=0.1
  106. start = time.monotonic()
  107. for i in range(0,100000):
  108.     out=i*0.1*out
  109. write_out("float multi", time.monotonic()-start)
  110.  
  111. out=0.1
  112. start = time.monotonic()
  113. for i in range(0,100000):
  114.     out=i/0.1 + out
  115. write_out("float divide multi", time.monotonic()-start)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top