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!