From 63c02c9ff5aaf2d9a5b65e82bdc362a223e751a9 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Tue, 19 Dec 2023 17:08:57 +0100 Subject: [PATCH] print_thoughts_about PeriodCounter.inc() --- performance/out/some_script.txt | 9 +++++++- performance/some_script.py | 40 +++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/performance/out/some_script.txt b/performance/out/some_script.txt index 7ae409a..3791013 100644 --- a/performance/out/some_script.txt +++ b/performance/out/some_script.txt @@ -1,7 +1,14 @@ -1_000 iterations of _prev_tup in 1.608ms. The main thing we care about is not this little +## _prev_tup() + +1_000 iterations of _prev_tup in 1.608mss. The main thing we care about is not this little private helper though, but PeriodCounter.inc(). Let's test that next. On testing: I noticed variations of a factor 2 even running these tests only a couple of times. For now I picked the slow results for a check in. +## PeriodCounter.inc() + +1_000 iterations of PeriodCounter.inc() in 82.716ms. We care about evaluation of some event more though. Let's +test that next. + diff --git a/performance/some_script.py b/performance/some_script.py index a4cd1b7..a89c734 100644 --- a/performance/some_script.py +++ b/performance/some_script.py @@ -1,6 +1,10 @@ +import random import time +from datetime import datetime, timezone -from bugsink.period_counter import _prev_tup +from bugsink.period_counter import _prev_tup, PeriodCounter + +from performance.bursty_data import generate_bursty_data, buckets_to_points_in_time # this file is the beginning of an approach to getting a handle on performance. @@ -21,7 +25,9 @@ def print_thoughts_about_prev_tup(): for i in range(1_000): v = _prev_tup(v) - print(f"""1_000 iterations of _prev_tup in {t.elapsed:.3f}ms. The main thing we care about is not this little + print(f"""## _prev_tup() + +1_000 iterations of _prev_tup in {t.elapsed:.3f}ms. The main thing we care about is not this little private helper though, but PeriodCounter.inc(). Let's test that next. On testing: I noticed variations of a factor 2 even running these tests only a couple of times. For now I picked the @@ -31,6 +37,36 @@ slow results for a check in. def print_thoughts_about_inc(): + random.seed(42) + + pc = PeriodCounter() + + # make sure the pc has some data before we start + for point in buckets_to_points_in_time( + generate_bursty_data(num_buckets=350, expected_nr_of_bursts=10), + datetime(2020, 10, 15, tzinfo=timezone.utc), + datetime(2021, 10, 15, 10, 5, tzinfo=timezone.utc), + 10_000, + ): + + pc.inc(point) + + points = buckets_to_points_in_time( + generate_bursty_data(num_buckets=25, expected_nr_of_bursts=5), + datetime(2021, 10, 15, 10, 5, tzinfo=timezone.utc), + datetime(2021, 10, 16, 10, 5, tzinfo=timezone.utc), + 1000) + + with passed_time() as t: + for point in points: + pc.inc(point) + + print(f"""## PeriodCounter.inc() + +1_000 iterations of PeriodCounter.inc() in {t.elapsed:.3f}ms. We care about evaluation of some event more though. Let's +test that next. +""") print_thoughts_about_prev_tup() +print_thoughts_about_inc()