[2/6] let's remove multiple inheritance (NoArithMeths)
[sympy.git] / bin / bench_float.py
blobb75d7e39162a3a08a43eb2d664adf73e437a55b7
1 # basic benchmark for the Float class
3 from time import clock
4 from random import *
5 from sympy.numerics import *
6 from sympy.numerics.functions import *
7 from sympy.numerics.functions2 import *
9 w = """
10 def f(N):
11 xs = []
12 seed(1234)
13 for i in range(N):
14 x = Float(random() * 2.0**randint(-10, 10)) ** 0.5
15 y = Float(random() * 2.0**randint(-10, 10)) ** 0.5
16 x *= choice([1, -1])
17 y *= choice([1, -1])
18 xs.append((x, y))
19 t1 = clock()
20 for x, y in xs:
22 t2 = clock()
23 return int(N/(t2-t1))
25 tests.append(("OP", f))
26 """
28 tests = []
29 def deftest(op):
30 exec w.replace("OP", op)
32 atests = ["x + y", "x - y", "x * y", "x / y", "x == y",
33 "x < y", "abs(x)", "abs(x)**0.5", "exp(x)", "sin(x)",
34 "tan(x)", "atan(x)"]
36 for test in atests:
37 deftest(test)
39 precs = [15, 30, 100, 500, 1000]
41 def runtests():
42 print "\n prec (dps) =",
43 for prec in precs:
44 print "%7s" % prec,
45 print
46 print "-" * 75
47 for name, test in tests:
48 print ("%12s" % name), ":",
49 for prec in precs:
50 Float.setdps(prec)
51 print "%7s" % test(max(50, 5000//prec)),
52 Float.revert()
53 print
55 print "\nFloat timings (operations / second)"
57 runtests()