def test_class_decorator(self):
        Clocked.initialize('test class decorator')

        TestDecorators.TestClassObj.delay_method()
        t = [i for i in Clocked.get('.*delay_method.*')]
        self.assertEqual(1, len(t))
        t = t[0]
        self._assert(20-2, t.duration_milliseconds, 20+2)
    def test_static_method(self):
        Clocked.initialize('test function and class decorators')

        TestDecorators.TestStaticMethod.delay_method()
        t = [i for i in Clocked.get('.*delay_method.*')]
        self.assertEqual(1, len(t))
        t = t[0]
        self._assert(20-2, t.duration_milliseconds, 20+2)
    def test_function_decorator(self):
        Clocked.initialize('test function decorator')

        TestDecorators.TestFunctionObj.delay_method()
        t = [i for i in Clocked.get('test_clocked.delay_method.*')]
        self.assertEqual(1, len(t))
        t = t[0]
        self._assert(20 - 2, t.duration_milliseconds, 20 + 2)
    def test_static_method(self):
        Clocked.initialize('test function and class decorators')

        TestDecorators.TestStaticMethod.delay_method()
        t = [i for i in Clocked.get('.*delay_method.*')]
        self.assertEqual(1, len(t))
        t = t[0]
        self._assert(20 - 2, t.duration_milliseconds, 20 + 2)
    def test_raw_simple(self):
        """ Simple raw test using Clocked object. """
        Clocked.initialize('test raw simple')

        with Clocked('loop 1'):
            for i in range(4):
                with Clocked('loop 2'):
                    for j in range(2):
                        with Clocked('loop 3'):
                            for j in range(2):
                                self.ten_ms()
                    for j in range(2):
                        with Clocked('loop 4'):
                            for j in range(2):
                                self.ten_ms()

        expected_total_time = 320
        delta_upper_bound = 10

        Clocked.verbose_report()
        Clocked.hotspot_report()
        print('')

        total = 0.0
        for timing in Clocked.get('loop 3'):
            total += timing.duration_milliseconds
        d = delta_upper_bound / 2
        e = expected_total_time / 2
        self._assert(e - d, total, e + d)

        total = 0.0
        for timing in Clocked.get('loop 4'):
            total += timing.duration_milliseconds
        d = delta_upper_bound / 2
        e = expected_total_time / 2
        self._assert(e - d, total, e + d)

        total = 0.0
        for timing in Clocked.get('loop 2'):
            total += timing.duration_milliseconds
        d = delta_upper_bound
        e = expected_total_time
        self._assert(e - d, total, e + d)
Exemple #6
0
 def get_with_on(self):
     Clocked.initialize('template')
     t = timeit.Timer(self._with)
     t.timeit(ITERATIONS)
     elapsed = t.timer()
     return elapsed
 def raises():
     with Clocked('test exception'):
         raise ValueError('some value error')
    def test_raw_simple(self):
        """ Simple raw test using Clocked object. """
        Clocked.initialize('test raw simple')

        with Clocked('loop 1'):
            for i in range(4):
                with Clocked('loop 2'):
                    for j in range(2):
                        with Clocked('loop 3'):
                            for j in range(2):
                                self.ten_ms()
                    for j in range(2):
                        with Clocked('loop 4'):
                            for j in range(2):
                                self.ten_ms()

        expected_total_time = 320
        delta_upper_bound = 10

        Clocked.verbose_report()
        Clocked.hotspot_report()
        print('')

        total = 0.0
        for timing in Clocked.get('loop 3'):
            total += timing.duration_milliseconds
        d = delta_upper_bound / 2
        e = expected_total_time / 2
        self._assert(e - d, total, e + d)

        total = 0.0
        for timing in Clocked.get('loop 4'):
            total += timing.duration_milliseconds
        d = delta_upper_bound / 2
        e = expected_total_time / 2
        self._assert(e - d, total, e + d)

        total = 0.0
        for timing in Clocked.get('loop 2'):
            total += timing.duration_milliseconds
        d = delta_upper_bound
        e = expected_total_time
        self._assert(e - d, total, e + d)
 def get_with_on(self):
     Clocked.initialize('template')
     t = timeit.Timer(self._with)
     t.timeit(ITERATIONS)
     elapsed = t.timer()
     return elapsed