kandinsky_benchmark.py

Created by cent20

Created on June 17, 2022

1.37 KB

D’après une idée de zetamap A benchmark to calculate speed of graphic methods.


# https://my.numworks.com/python/zetamap/kandinsky_benchmark

from kandinsky import *
from ion import keydown
from time import monotonic
from math import cos, sin, log10


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(">>> ")

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.