Skip to content

Can this library be used in production code, does it save all the timing values. #51

Open

Description

@vik748

I am wondering if the Time class stores all the timing values it receives. I was intrigued since median computation would require something like that. If it does store it, does that mean the data structure grows unbounded?

Activity

  1. mvanholsteijn commented on Jan 6, 2025

    @mvanholsteijn

    TLDR; unless you explicitly call timer.timers.clear() it will grow unbounded.

    https://github.com/realpython/codetiming/blob/main/codetiming/_timers.py#L24-L33

    The Timers class is a class attribute of the Timer. It keeps a record of all starts and stops. So you need to clear it yourself every now and them.

  2. dogganon commented on Mar 9, 2026

    @dogganon

    The Timers class is a class attribute of the Timer

    It truly should not. It makes more sense for the global Timers to be a default; users should be allowed to pass their own Timers while instantiating the Timer instance.

    Ideally Timers should be a factory such that all Timer objects created under it are bound by the factory's lifecycle. So in terms of object relationship, the API has it backwards.

    @mvanholsteijn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions