示例#1
0
 def test_time_20(self):
     """TestRepCodeFrom68Time.test_time_20(): 1e5 word conversion from FileRead: """
     i = 0
     numWords = 1e5
     myWord = b'\x44\x4c\x80\x00'
     wordsInPr = int(
         (PhysRec.PR_MAX_LENGTH - PhysRec.PR_PRH_LENGTH) / len(myWord))
     # Suc no Pre: 1
     # Pre no Suc: 2
     # Suc and Pre: 3
     prContStart = PhysRec.PR_PRH_LEN_FORMAT.pack(PhysRec.PR_PRH_LENGTH + len(myWord)*wordsInPr) \
         + PhysRec.PR_PRH_ATTR_FORMAT.pack(1) \
         + (myWord * wordsInPr)
     # Absent Physical Record trailer
     prContBody = PhysRec.PR_PRH_LEN_FORMAT.pack(PhysRec.PR_PRH_LENGTH + len(myWord)*wordsInPr) \
         + PhysRec.PR_PRH_ATTR_FORMAT.pack(3) \
         + (myWord * wordsInPr)
     # Absent Physical Record trailer
     prContEnd = PhysRec.PR_PRH_LEN_FORMAT.pack(PhysRec.PR_PRH_LENGTH + len(myWord)*wordsInPr) \
         + PhysRec.PR_PRH_ATTR_FORMAT.pack(2) \
         + (myWord * wordsInPr)
     # Absent Physical Record trailer
     # How many physical records
     numPr = int(numWords / wordsInPr)
     numPrBody = numPr - 2
     assert (numPrBody >= 0)
     # Python code first
     myBy = io.BytesIO(prContStart + prContBody * numPrBody + prContEnd)
     myFile = File.FileRead(theFile=myBy,
                            theFileId='MyFile',
                            keepGoing=False)
     i = 0
     tS = time.clock()
     while i < wordsInPr * numPr:
         pRepCode.read68(myFile)
         i += 1
     tE_P = time.clock() - tS
     self.assertFalse(myFile.hasLd())
     sys.stderr.write('Python: %.3f %8.0f words/S ' %
                      (tE_P, numWords / tE_P))
     # Now Cython code
     myBy = io.BytesIO(prContStart + prContBody * numPrBody + prContEnd)
     myFile = File.FileRead(theFile=myBy,
                            theFileId='MyFile',
                            keepGoing=False)
     i = 0
     tS = time.clock()
     while i < wordsInPr * numPr:
         RepCode.read68(myFile)
         i += 1
     tE_C = time.clock() - tS
     self.assertFalse(myFile.hasLd())
     sys.stderr.write('Cython: %.3f %8.0f words/S ' %
                      (tE_C, numWords / tE_C))
     sys.stderr.write('%.1f%% (x%.1f) ' % ((100.0 *
                                            (tE_C / tE_P)), tE_P / tE_C))
示例#2
0
    def test_12_p(self):
        """TestRepCodeFrom68Python.test_12_c(): read68(0xBBB38000) -> -153.0 Python."""
        myBy = io.BytesIO(
            PhysRec.PR_PRH_LEN_FORMAT.pack(PhysRec.PR_PRH_LENGTH + 4) \
            + PhysRec.PR_PRH_ATTR_FORMAT.pack(0) \
            + b'\xbb\xb3\x80\x00' \
            # Absent Physical Record trailer

        )
        myFile = File.FileRead(theFile=myBy,
                               theFileId='MyFile',
                               keepGoing=True)
        self.assertEqual(pRepCode.read68(myFile), -153.0)
        self.assertFalse(myFile.hasLd())