benchmarksavage.py

Created by steveg1cmz

Created on April 05, 2024

1.16 KB

Implement savage benchmark. Works without clock.

Platforms: Numworks, Pyscript


"""Savage Benchmark.
"""
__version__="0.2"
crid="Savage Benchmark \nimplement by SteveG1CMZ"

from math import *
from math import log as ln #readability

try: from time import *
except:
  def monotonic(): #where time not defined
    return float("NaN") #precludes round to int

unit=1000 #ms
units="ms"

def savage1():
  aa=1
  for i in range(0,2499): #python for
    aa=tan(atan(exp(ln(sqrt(aa*aa)))))+1;
  return aa

def savagetime1():
  t=monotonic()
  s=savage1()
  t=monotonic()-t
  return t

def savagetimer(r):
  #repeat test for average time
  if r==0: return []
  t=0
  tmax=0
  tmin=100000 #arbitrary
  for i in range(r):
   t1=savagetime1()
   if t1>tmax: tmax=t1
   if t1<tmin: tmin=t1
   t=t+t1
  tavg=t/r
  unit=1000
  result=[round(tmin*unit,3), round(tavg*unit,3),round(tmax*unit,3)]
  
  #print(result)
  return result
  
if __name__=="__main__" or True:
  print(crid)
  
  t=savagetime1()
  print(savage1())
  print("in",round(t*unit,3),units)
  if not(isnan(t)):
    k=1000 #repeat test to get average
    print(k,"runs","min/average/max:")
    result=savagetimer(k)
    print(result,units)
    #Note:
    #This does not include the 1st run!

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.