Benchmark calculatons of functions using fastmath
Code: "func_fastcalculations.py". Programming language: Python
DMelt Version 1.8. Last modified: 05/16/2017. License: Pro
https://datamelt.org/code/cache/func_fastcalculations_2010.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from jhplot import *
import time
HParam.setFastMath() # apply fast calculations for functions
# comment out this code for full precision (java Math)
print "Fast calculations are set to ", HParam.isFastMath(), " working .."
a=F1D("acos(x)+asin(x)+atan(2*x)+cos(x)")
s=0;
start = time.time()
for i in range (10000000):
s=s+a.eval(0.99-0.00000001*i)
end = time.time()
print "fast calculation result=",s, " time used (sec)",end - start
HParam.setFastMath(False)
print "Fast calculations are set to ", HParam.isFastMath(), " working .."
s=0;
start = time.time()
for i in range (10000000):
s=s+a.eval(0.99-0.00000001*i)
end = time.time()
print "fast calculation result=",s, " time used (sec)",end - start
You see the box below because you did not login.