Skip to content
Jacob Morris edited this page Jan 21, 2017 · 31 revisions

Class Attributes

  • seconds -> abbreviated s
  • milliseconds -> abbreviated ms (10-3 s)
  • microseconds -> typically abbreviation is μs, but to avoid UNICODE issues, it is abbreviated us (10-6 s)
  • nanoseconds -> abbreviated ns (10-9 s)

Constructor

  • PyTimer(*args, **kwargs)
  • args : varied (optional) -> the first arugment will be used to determine whether or not to automatically run start() if it is present. Otherwise, start() is automatically called
    • start: bool (optional) -> Automatically run start() when creating object
  • kwargs : varied (optional) -> keyword arguments, five of which are checked for
    • round: int (optional) -> Number of digits to round values to
    • run: bool (optional) -> Do functions calls to timer object do anything, useful for disabling timer without removing code
    • collect: bool (optional) -> Collect all data the is, or would be, displayed
    • display: bool (optional) -> Print outputs to console
    • units: str (optional) -> Units to display times in, must be in (PyTimer.seconds, PyTimer.milliseconds, PyTimer.microseconds, PyTimer.nanoseconds), if not specified, then value is converted to nearest one

Functions

  • average(i): int -> Returns average of i'th split, or None if empty split or False if i is an invalid index

  • i: int -> Index of split to determine average for

  • averages(): list -> Returns list of averages for every split, if position i is empty, then list[i] is None

  • decorator(function): callable -> For use only as a decorator like @timer.decorator, this allows the function to be timed when it is called. WARNING: Do not use decorator with recursive function as this will lead to a spiral of calls within the decorator. Instead, use the evaluate() method.

  • deviation(i): float -> Returns the standard deviation of split i or None if i is empty split otherwise False if i is an invalid index

  • i: int -> Index of split to determine standard deviation for

  • deviations(): list -> Returns list of standard deviations for every split, if split i is empty then list[i] is None

  • display_average(i) -> Display average of split i if valid index, if empty split or invalid index than an appropriate messages is displayed

  • i: int -> index of split to display average for

  • display_averages() -> Display averages for every split, if split is empty than it is skipped

  • display_deviation(i) -> Display standard deviation for split i, if empty split or invalid index than an appropriate message is displayed

  • i: int -> index of split to display standard deviation for

  • display_deviations() -> Display standard deviations for all splits, if split is empty than it is skipped

  • display_split(i) -> Display all logged values in split i, if split is empty or invalid index than an appropriate message is displayed

  • i: int -> index of split to display logged values for

  • display_splits() -> Display all logged values for all splits, if split is empty than it is skipped

  • evaluate(block, *args, **kwargs) -> Runs block reps times, then calls log() and repeats iterations times. split() is called at end with message based on text of block, or name of function, or message if specified

  • block: (str or callable) -> string block of code, or function to be timed

  • args: varied -> arguments to be passed into block if it is a function

  • kwargs : varied -> keyword arguments, three are specifically reservered for this method, the others are passed into block if it is a function

    • reps: int (optional) -> number of reps, defaults to 10
    • iterations: int (optional) -> number of iterations, defaults to 10
    • message: str (optional) -> message to use for split, if not specified, than the message is block.__name__ if block is a function. Otherwise, the message is block if it is a str

  • log(message="") -> Log time since start, last log, last split, or last resume, depending on which happened most recently

  • message: str (optional) -> message to attach to log

  • overall_time(): float -> time elapsed since start() or reset() in seconds. This includes time spend executing PyTimer calls.

  • pause() -> pause timer

  • reset() -> clear all recorded values, call start() to update internal time values

  • resume() -> start back from pause(), update internal time values

  • setup_decorator(**kwargs) -> allow number of reps and iterations to be set for decorator

  • kwargs : varied (optional) -> keyword arguments, two of which are specified for this method

    • reps: int (optional) -> number of reps for decorator, defaults to 1
    • iterations: int (optional) -> number of iterations for decorator, defaults to 10

  • split(message="") -> Create separate group of logs

  • message: str (optional) -> message to be attached to split, used as name when displaying anything associated with this split

  • start() -> setup internal time values, must be called manually if start is set to False when object was created

  • times(i): list -> returns list of elapsed times for split i or None if invalid index

  • i: int -> index for split w/ elapsed times

  • write_output(fp) -> will write all collected output to file path fp if collect was set to True when creating object, otherwise an appropriate message will be displayed. PermissionError will be thrown if file path cannot be written to.

  • fp: str -> file path to write file to

Clone this wiki locally