Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import board
- from digitalio import DigitalInOut, Direction, Pull
- import neopixel
- import storage
- import sys
- def write_out(markname, marktime):
- try:
- with open("/benchmarks.csv", "a") as bench:
- bench.write(markname+","+circuitpythonversion+",")
- bench.write('{0:f}\n'.format(marktime))
- except OSError as e:
- pass
- print(markname, circuitpythonversion, marktime, sep=",")
- #circuit python benchmark
- print("running benchmarks")
- print(str(sys.implementation[1][0]) + "-" + str(sys.implementation[1][1])+"-"+str(sys.implementation[1][2]))
- circuitpythonversion = str(sys.implementation[1][0]) + "-" + str(sys.implementation[1][1])+"-"+str(sys.implementation[1][2])
- #Storage
- start = time.monotonic()
- try:
- with open("/test.txt", "a") as fp:
- for i in range(20):
- fp.write('test')
- fp.flush()
- with open("/benchmarks.csv", "a") as bench:
- bench.write("filesystem benchmark,")
- bench.write(circuitpythonversion)
- bench.write(',{0:f}\n'.format(time.monotonic()-start))
- except OSError as e:
- print("write error -- unable to perform filesystem benchmark")
- #Neopixel
- pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.3, auto_write=False)
- start = time.monotonic()
- for i in range(0,200):
- pixels.fill((255,0,0))
- pixels.show()
- pixels.fill((0,255,0))
- pixels.show()
- write_out("neopixel flicker", time.monotonic()-start)
- def rainbow_cycle():
- for x in range(255):
- for y in range(10):
- rc_index = (x * 256 // 10) + y
- pixels[y] = wheel(rc_index & 255)
- pixels.show()
- def wheel(pos):
- # Input a value 0 to 255 to get a color value.
- # The colours are a transition r - g - b - back to r.
- if pos < 0 or pos > 255:
- return (0, 0, 0)
- if pos < 85:
- return (255 - pos * 3, pos * 3, 0)
- if pos < 170:
- pos -= 85
- return (0, 255 - pos * 3, pos * 3)
- pos -= 170
- return (pos * 3, 0, 255 - pos * 3)
- start = time.monotonic()
- for i in range(2):
- rainbow_cycle()
- write_out("neopixel rainbow", time.monotonic()-start)
- #GPIO
- led = DigitalInOut(board.D13)
- led.direction = Direction.OUTPUT
- start = time.monotonic()
- for i in range(0,100000):
- led.value = True
- led.value = False
- write_out("GPIO on/off benchmark", time.monotonic()-start)
- out = 0
- start = time.monotonic()
- for i in range(0,100000):
- out= out+i+i
- write_out("integer sum", time.monotonic()-start)
- out = 0
- start = time.monotonic()
- for i in range(0,100000):
- out= out + i*i
- write_out("integer multi", time.monotonic()-start)
- out=0.1
- start = time.monotonic()
- for i in range(0,100000):
- out=out+i+0.1
- write_out("float sum", time.monotonic()-start)
- out=0.1
- start = time.monotonic()
- for i in range(0,100000):
- out=i*0.1*out
- write_out("float multi", time.monotonic()-start)
- out=0.1
- start = time.monotonic()
- for i in range(0,100000):
- out=i/0.1 + out
- write_out("float divide multi", time.monotonic()-start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement