1 """Some basic performance tests for the wrapper class"""
6 def ops_sec(stmt
, setup
):
13 timer
= timeit
.Timer(stmt
, setup
)
14 iters
, time
= timer
.autorange()
18 erate
= rate
/ 1000000000
21 erate
= rate
/ 1000000
30 print('{} ops, {} s, {} {}/s\n'.format(iters
, time
, erate
, unit
))
33 setup
= """import sfpy
34 import SoftPosit.python.softposit as sp1
35 import SoftPosit.python._softposit as sp2
38 sfpy_a = sfpy.Posit16(1.3)
39 sfpy_b = sfpy.Posit16(-0.5)
40 sfpy_c = sfpy.Posit16(15.0)
41 sfpy_q = sfpy.Quire16(0)
43 sp1_a = sp1.posit16(1.3)
44 sp1_b = sp1.posit16(-0.5)
45 sp1_c = sp1.posit16(15.0)
49 sp2_a = sp2.convertDoubleToP16(1.3)
50 sp2_b = sp2.convertDoubleToP16(-0.5)
51 sp2_c = sp2.convertDoubleToP16(15.0)
52 sp2_q = sp2.new_quire16_t()
55 ops_sec('pass', setup
)
56 ops_sec('sfpy.Posit16(0)', setup
)
57 ops_sec('sp1.posit16(0)', setup
)
58 #ops_sec('sp2.new_posit16_t()', setup)
60 ops_sec('one + zero', setup
)
61 ops_sec('sfpy_a + sfpy_b', setup
)
62 ops_sec('sp1_a + sp1_b', setup
)
63 #ops_sec('sp2_a + sp2_b', setup)
65 ops_sec('sfpy_c += sfpy_b', setup
)
67 # ops_sec('P8(0)', setup)
68 # ops_sec('P8("0")', setup)
69 # ops_sec('P8.from_bits(0)', setup)
71 # ops_sec('1.1 + 2', setup)
72 # ops_sec('a + b', setup)
73 # ops_sec('a.add(b)', setup)
74 # ops_sec('zero += 1', setup)
75 # ops_sec('a += b', setup)
76 # ops_sec('a.iadd(b)', setup)
78 # ops_sec('q.fdp_add(b, c)', setup)