A benchmark to calculate speed of graphic methods.
import kandinsky from ion import keydown from time import monotonic from math import cos, sin, log10 def wait_key(): while True: for i in range(53): if keydown(i): while keydown(i): pass return i def test(method, *args): func = getattr(kandinsky, method) values = [] for i in range(300): time_is = monotonic() func(*args) values.append(monotonic()-time_is) kandinsky.fill_rect(0, 0, 320, 220, "white") print(method, "speed:", sum(values)/len(values)*10**6, "μs") kandinsky.draw_string("Welcome to kandinsky speed test program", 5, 50) kandinsky.draw_string("Press a key to start test ...", 15, 70) wait_key() kandinsky.fill_rect(0, 0, 320, 220, "white") test("set_pixel", 10, 10, "black") print("100*100: ", end='') test("fill_rect", 10, 10, 100, 100, "black") print("1*1: ", end='') test("fill_rect", 10, 10, 1, 1, "black") test("draw_string", "test string", 10, 10) for i in range(300): kandinsky.set_pixel(10+i, 10, (cos(i)*1000, sin(i)*1000, log10(i+1)*1000)) values = [] for i in range(300): time_is = monotonic() kandinsky.get_pixel(10+i, 10) values.append(monotonic()-time_is) print("get_pixel speed:", sum(values)/len(values)*10**6, "μs") for i in range(300): time_is = monotonic() kandinsky.color((cos(i)*1000, sin(i)*1000, log10(i+1)*1000)) values.append(monotonic()-time_is) print("color speed:", sum(values)/len(values)*10**6, "μs") input(">>> ")