dhasimplebench.py

Created by mobluse

Created on June 26, 2023

712 Bytes

“Ahl’s Simple Benchmark” from the magazine Creative Computing. The last result is the average of the earlier 10. Before that are 10 runs, because it speeds up when you run it a few times. I got accuracy 6.821210263296962e-13, random 12.58937371239872, time 00:00:00.92350 on my Numworks N0110 version 21.0.0. See https://en.wikipedia.org/wiki/Creative_Computing_Benchmark.


from math import *
from random import *
from time import *
def dhasimplebench():
  # Ahl's Simple Benchmark
  r=0
  s=0
  for n in range(1,101):
    a=n
    for i in range(1,11):
      a=sqrt(a); r=r+random()
    for i in range(1,11):
      a=a**2; r=r+random()
    s=s+a
  print(abs(1010-s/5))
  print(abs(1000-r))
  return (abs(1010-s/5),abs(1000-r))
def benchmark10():
  ran=0
  acc=0
  for i in range(10):
    t0=monotonic()
    b=dhasimplebench()
    acc+=b[0]
    ran+=b[1]
    print("%08.5f s"%(monotonic()-t0))
  return (acc,ran)
seed()
benchmark10()
t0=monotonic()
(acc,ran)=benchmark10()
print("Average of 10:")
print(acc/10)
print(ran/10)
print("%08.5f s"%((monotonic()-t0)/10))

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.