def test_timing_add(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += 1 self.assertEquals(1, len(stats.get_timing_stats(reset=False))) stats.add_timing("foobar", timing.TimingStat(1, 0, 0)) self.assertEquals(2, len(stats.get_timing_stats(reset=False))) self.assertEquals(1, stats.get_timing_stats(reset=True)["foobar"].count) stats.add_timing("foobar", timing.TimingStat(3, 0, 0)) self.assertEquals(3, stats.get_timing_stats(reset=False)["foobar"].count)
def test_timing_reset(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(1, stats.get_timing_stats(reset=False)["hundred"].count) with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(2, stats.get_timing_stats(reset=False)["hundred"].count) self.assertEqual(2, stats.get_timing_stats(reset=True)["hundred"].count) with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(1, stats.get_timing_stats(reset=False)["hundred"].count)
def test_timing_bundle(self): timing_stat = timing.TimingStat(3, 20, 10, 15.0, 50.0, histogram.Histogram(10, 15, 20)) stats.add_timing("test", timing_stat) stats.add_timing("test", 25) test = stats.get_timing_stats(reset=False)["test"] self.assertEqual(4, test.count) self.assertEqual(17, test.average) self.assertEqual(6, int(test.std_dev)) stats.clear_all() timing_stat1 = timing.TimingStat(2, 25, 15, 20.0, 50.0, histogram.Histogram(15, 25)) timing_stat2 = timing.TimingStat(2, 20, 10, 15.0, 50.0, histogram.Histogram(10, 20)) stats.add_timing("test", timing_stat1) stats.add_timing("test", timing_stat2) test = stats.get_timing_stats(reset=False)["test"] self.assertEqual(4, test.count) self.assertEqual(17, test.average) self.assertEqual(6, int(test.std_dev))
def test_timings_report(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += i timings = stats.get_timing_stats() self.assertEquals(["hundred"], timings.keys()) self.assertEquals(1, timings["hundred"].count) self.assertEquals(timings["hundred"].average, timings["hundred"].min) self.assertEquals(timings["hundred"].average, timings["hundred"].max)
def test_timing_report_sorted(self): stats.add_timing("alpha", timing.TimingStat(1, 0, 0)) string = str(stats.get_timing_stats(reset=False)["alpha"]) self.assertEquals("(average=0, count=1, maximum=0, minimum=0, p25=0, p50=0, p75=0, p90=0, p99=0, p999=0, p9999=0, standard_deviation=0)", string)