Пример #1
0
    def test_class_sorting_is_fast(self):
        sz = 10000000
        
        #burn the calculation in.
        self.classSortingTest(sz, useClass=True)
        self.classSortingTest(sz, useClass=False)
        
        t0 = time.time()

        with PerformanceTestReporter.RecordAsPerfTest("python.datatasks.sort_class_instances"):
            self.classSortingTest(sz, useClass=True)

        t1 = time.time()

        with PerformanceTestReporter.RecordAsPerfTest("python.datatasks.sort_integers"):
            self.classSortingTest(sz, useClass=False)

        t2 = time.time()

        intTime = t2 - t1
        classTime = t1 - t0

        self.assertTrue(classTime < intTime * 5, "Times (ints) %s and (classes) %s were not very close." % (intTime, classTime))

        print intTime, " to sort ints"
        print classTime, " to sort class instances"
Пример #2
0
    def test_large_string_parsing_perf(self):
        def f(ct, passCt):
            x = "1,2,3,4," * ct
            res = 0
            for _ in xrange(passCt):
                ix = 0
                while ix < len(x):
                    res = res + int(x[ix:ix + 1]) + 12341234
                    ix = ix + 2
            return res

        self.evaluateWithExecutor(f, 1000000, 1)

        with PerformanceTestReporter.RecordAsPerfTest("pyfora.string_to_int"):
            self.evaluateWithExecutor(f, 1000000, 10)