numworks_pybench.py

Created by 81lennoch

Created on February 02, 2023

2.23 KB


"""
>> https://my.numworks.com/python/81lennoch/numworks_pybench_beta <<
"""

import time
import matplotlib.pyplot as plt


print(
      "\n--------------------------------"
      "\n\nStarting..."
      "\n\nStarting Image Generation..."
     )

def generate_random_image(width, height):
    image = Image.new("RGB", (width, height))
    pixels = image.load()
    for i in range(width):
        for j in range(height):
            pixels[i, j] = (np.random.randint(0, 255), np.random.randint(
                0, 255), np.random.randint(0, 255))
    return image

start_time = time.perf_counter()
image = generate_random_image(300, 300)
end_time = time.perf_counter()

image_gen_time = end_time - start_time
score1 = 100 / image_gen_time * 5.5


print("Starting Graph Generation...")

def generate_plot(x, y):
    plt.plot(x, y)
    return plt.figure()

start_time = time.perf_counter()
x = np.linspace(0, 20 * np.pi, 1000)
y = np.sin(x) * np.exp(-0.1 * x)
generate_plot(x, y)
end_time = time.perf_counter()

plot_gen_time = end_time - start_time
score2 = 100 / plot_gen_time * 2.1


print("Starting Calculating Pi...")

def calculate_pi(n_terms):
    numerator = 4.0
    denominator = 1.0
    operation = 1.0
    pi = 0.0
    for _ in range(n_terms):
        pi += operation * (numerator / denominator)
        denominator += 2.0
        operation *= -1.0
    return pi

start_time = time.perf_counter()
calculate_pi(100000000)
end_time = time.perf_counter()

pi_calc_time = end_time - start_time
score3 = 4000 / pi_calc_time * 1.8

total_time = image_gen_time + plot_gen_time + pi_calc_time
total_score = score1 + score2 + score3


#print("Done!\n\n")
#print("\n== Image Generation ==")
#print("\nSize         : 300x300")
#print(f"\nTime         :", image_gen_time)
#print(f"\nScore        : {score1}")
#print("\n\n== Graph Generation ==")
#print(f"\nTime         : {plot_gen_time}s")
#print(f"\nScore        : {score2}")
#print("\n\n== Operations ==")
#print("\nOperations   : 100000000")
#print(f"\nTime         : {pi_calc_time}s")
#print(f"\nOperations/s : {100000000/pi_calc_time}")
#print(f"\nScore        : {score3}")
#print(f"\n\n\nTotal Time   : {total_time}")
#print(f"\nTotal Score  : {total_score}")
#print("\n\n--------------------------------")

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.