def test_time_01(self):
     """TestRepCodeFrom68Time.test_time_01(): tests conversion of 1e6 of same word - Python code."""
     i = 0
     num = 1e6
     tS = time.clock()
     while i < num:
         pRepCode.from68(0xBBB38000)
         i += 1
     self.writeTimeToStdErr(tS, 68, num)
 def test_time_11(self):
     """TestRepCodeFrom68Time.test_time_11(): tests conversion of 1e5 random words - Python code."""
     i = 0
     num = 1e5
     tS = time.clock()
     while i < num:
         pRepCode.from68(self.randWord(1, 8, 23))
         i += 1
     self.writeTimeToStdErr(tS, 68, num)
Beispiel #3
0
 def time_struct_68(self, arg):
     my_struct = self.struct_compiled[arg]
     # buf_len = struct.calcsize(arg)
     with open(binary_path(20), 'rb') as f:
         while 1:
             b = f.read(arg)
             if len(b) != arg:
                 break
             for word in my_struct.unpack(b):
                 pRepCode.from68(word)
Beispiel #4
0
 def _readStructCompiled_p68(self, theFormat):
     # We exclude compilation time as in practice that is a one-of task
     myStruct = struct.Struct(theFormat)
     bufLen = struct.calcsize(theFormat)
     tS = time.clock()
     byteCount = 0
     fileCount = 0
     for aFileName in os.listdir(TEST_DIR):
         fileCount += 1
         with open(os.path.join(TEST_DIR, aFileName), 'rb') as f:
             while 1:
                 b = f.read(bufLen)
                 byteCount += len(b)
                 if len(b) != bufLen:
                     break
                 # Convert from RepCod 68
                 for w in myStruct.unpack(b):
                     pRepCode.from68(w)
     return fileCount, byteCount, (time.clock() - tS)
 def test_04(self):
     """TestRepCodeTo68LowExponent.test_04(): Special exponent tests, full range."""
     for e in range(-150, 128, 1):
         rcWord = pRepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(pRepCode.from68(rcWord)))
     for e in range(-150, 128, 1):
         rcWord = cRepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(cRepCode.from68(rcWord)))
     for e in range(-150, 128, 1):
         rcWord = RepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(RepCode.from68(rcWord)))
 def test_time_02(self):
     """TestRepCodeFrom68Time.test_time_00(): tests conversion of 1e6 of same word - Cython time c.f. Python: """
     i = 0
     num = 1e6
     tS = time.clock()
     while i < num:
         cRepCode.from68(0xBBB38000)
         i += 1
     tE_C = time.clock() - tS
     #print 'C time: %.3f rate %8.0f words/S' % (tE_C, num/tE_C)
     i = 0
     tS = time.clock()
     while i < num:
         pRepCode.from68(0xBBB38000)
         i += 1
     tE_P = time.clock() - tS
     #print 'Python time: %.3f rate %8.0f words/S' % (tE_P, num/tE_P)
     #sys.stderr.write('Cython: %.3f% ' % tE_C)
     #sys.stderr.write('Python: %.3f% ' % tE_P)
     sys.stderr.write('%.1f%% (x%.1f) ' % ((100.0 *
                                            (tE_C / tE_P)), tE_P / tE_C))
 def test_min(self):
     """TestRepCodeFrom68.test_min(): min by bit stuffing."""
     myWord = 1
     myWord <<= 8
     myWord |= 1
     myWord <<= 23
     # 0 exponent
     myWord = 0x80000000
     #print
     #print RepCode.from68(myWord)
     self.assertEqual(RepCode.from68(myWord), RepCode.minValue(68))
     self.assertEqual(pRepCode.from68(myWord), RepCode.minValue(68))
     self.assertEqual(cRepCode.from68(myWord), RepCode.minValue(68))
 def test_max(self):
     """TestRepCodeFrom68.test_max(): max by bit stuffing."""
     myWord = 0x7FFFFFFF
     f = RepCode.from68(myWord)
     #m,e = math.frexp(f)
     #print
     #print 'Max:', f
     #print 'm,e:', m,e
     #print 'm:      shifted 23', m * (1<<23)
     #print 'm: 1.0 / (1.0 - m)', 1.0 / (1.0 - m)
     #print '             2**23', 2**23
     #print '             1<<23', 1<<23
     #print('dir(RepCode)')
     #print(dir(RepCode))
     self.assertEqual(RepCode.from68(myWord), RepCode.maxValue(68))
     self.assertEqual(cRepCode.from68(myWord), RepCode.maxValue(68))
     self.assertEqual(pRepCode.from68(myWord), RepCode.maxValue(68))
 def test_02_00(self):
     """TestRepCodeTo68LowExponent.test_02_00(): from68() mantissa depression - pRepCode module."""
     #        print('0x00000001', RepCode.from68(0x00000001))
     self.assertEqual((0.5, -150), math.frexp(pRepCode.from68(0x00000001)))
     self.assertEqual((0.5, -149), math.frexp(pRepCode.from68(0x00000002)))
     self.assertEqual((0.5, -148), math.frexp(pRepCode.from68(0x00000004)))
     self.assertEqual((0.5, -147), math.frexp(pRepCode.from68(0x00000008)))
     self.assertEqual((0.5, -146), math.frexp(pRepCode.from68(0x00000010)))
     self.assertEqual((0.5, -145), math.frexp(pRepCode.from68(0x00000020)))
     self.assertEqual((0.5, -144), math.frexp(pRepCode.from68(0x00000040)))
     self.assertEqual((0.5, -143), math.frexp(pRepCode.from68(0x00000080)))
     self.assertEqual((0.5, -142), math.frexp(pRepCode.from68(0x00000100)))
     self.assertEqual((0.5, -141), math.frexp(pRepCode.from68(0x00000200)))
     self.assertEqual((0.5, -140), math.frexp(pRepCode.from68(0x00000400)))
     self.assertEqual((0.5, -139), math.frexp(pRepCode.from68(0x00000800)))
     self.assertEqual((0.5, -138), math.frexp(pRepCode.from68(0x00001000)))
     self.assertEqual((0.5, -137), math.frexp(pRepCode.from68(0x00002000)))
     self.assertEqual((0.5, -136), math.frexp(pRepCode.from68(0x00004000)))
     self.assertEqual((0.5, -135), math.frexp(pRepCode.from68(0x00008000)))
     self.assertEqual((0.5, -134), math.frexp(pRepCode.from68(0x00010000)))
     self.assertEqual((0.5, -133), math.frexp(pRepCode.from68(0x00020000)))
     self.assertEqual((0.5, -132), math.frexp(pRepCode.from68(0x00040000)))
     self.assertEqual((0.5, -131), math.frexp(pRepCode.from68(0x00080000)))
     self.assertEqual((0.5, -130), math.frexp(pRepCode.from68(0x00100000)))
     self.assertEqual((0.5, -129), math.frexp(pRepCode.from68(0x00200000)))
     self.assertEqual((0.5, -128), math.frexp(pRepCode.from68(0x00400000)))
Beispiel #10
0
 def test_04_p(self):
     """TestRepCodeFrom68Python.test_04_p(): from68(0x40000000) -> 0.0 Python."""
     self.assertEqual(pRepCode.from68(0x40000000), 0.0)
Beispiel #11
0
 def test_02_p(self):
     """TestRepCodeFrom68Python.test_02_p(): from68(0xBBB38000) -> -153.0 Python."""
     self.assertEqual(pRepCode.from68(0xBBB38000), -153.0)
Beispiel #12
0
 def test_01_p(self):
     """TestRepCodeFrom68Python.test_01_p(): from68(0x444C8000) -> 153.0 Python."""
     self.assertEqual(pRepCode.from68(0x444C8000), 153.0)
Beispiel #13
0
 def time_pRepCode_from(self):
     pRepCode.from68(0x444C8000)