Example #1
0
 def profile(profiler):
     with profiling(profiler):
         c1 = spawn(light)
         c2 = spawn(heavy)
         for c in [c1, c2]:
             join(c)
     stat1 = find_stat(profiler.stats, 'light')
     stat2 = find_stat(profiler.stats, 'heavy')
     return (stat1, stat2)
Example #2
0
 def profile(profiler):
     with profiling(profiler):
         c1 = spawn(light)
         c2 = spawn(heavy)
         for c in [c1, c2]:
             join(c)
     stat1 = find_stat(profiler.stats, 'light')
     stat2 = find_stat(profiler.stats, 'heavy')
     return (stat1, stat2)
Example #3
0
def test_profiler():
    profiler = Profiler(top_frame=sys._getframe())
    assert isinstance(profiler.stats, RecordingStatistics)
    assert isinstance(profiler.result(), FrozenStatistics)
    assert len(profiler.stats) == 0
    with profiling(profiler):
        factorial(1000)
        factorial(10000)
    stat1 = find_stat(profiler.stats, 'factorial')
    stat2 = find_stat(profiler.stats, '__enter__')
    stat3 = find_stat(profiler.stats, '__exit__')
    assert stat1.total_time != 0
    assert stat1.total_time == stat1.own_time
    assert stat1.own_time > stat2.own_time
    assert stat1.own_time > stat3.own_time
    assert stat1.calls == 2
    assert stat2.calls == 0  # entering to __enter__() wasn't profiled.
    assert stat3.calls == 1
Example #4
0
def test_profiler():
    profiler = Profiler(top_frame=sys._getframe())
    assert isinstance(profiler.stats, RecordingStatistics)
    assert isinstance(profiler.result(), FrozenStatistics)
    assert len(profiler.stats) == 0
    with profiling(profiler):
        factorial(1000)
        factorial(10000)
    stat1 = find_stat(profiler.stats, 'factorial')
    stat2 = find_stat(profiler.stats, '__enter__')
    stat3 = find_stat(profiler.stats, '__exit__')
    assert stat1.total_time != 0
    assert stat1.total_time == stat1.own_time
    assert stat1.own_time > stat2.own_time
    assert stat1.own_time > stat3.own_time
    assert stat1.calls == 2
    assert stat2.calls == 0  # entering to __enter__() wasn't profiled.
    assert stat3.calls == 1