Beispiel #1
0
def test_simple_profiler():
    p = Profiler()

    with p.profile("a"):
        time.sleep(3)

    with p.profile("a"):
        time.sleep(1)

    with p.profile("b"):
        time.sleep(2)

    with p.profile("c"):
        time.sleep(1)

    # different environments have different precision when it comes to time.sleep()
    # see: https://github.com/PyTorchLightning/pytorch-lightning/issues/796
    np.testing.assert_allclose(p.recorded_durations["a"], [3, 1], rtol=0.2)
    np.testing.assert_allclose(p.recorded_durations["b"], [2], rtol=0.2)
    np.testing.assert_allclose(p.recorded_durations["c"], [1], rtol=0.2)
def test_simple_profiler():
    p = Profiler()

    with p.profile("a"):
        time.sleep(3)

    with p.profile("a"):
        time.sleep(1)

    with p.profile("b"):
        time.sleep(2)

    with p.profile("c"):
        time.sleep(1)

    # different environments have different precision when it comes to time.sleep()
    np.testing.assert_almost_equal(p.recorded_durations["a"], [3, 1],
                                   decimal=1)
    np.testing.assert_almost_equal(p.recorded_durations["b"], [2], decimal=1)
    np.testing.assert_almost_equal(p.recorded_durations["c"], [1], decimal=1)