pg.utils.TimeIt

Accessible via pg.utils.TimeIt.

class TimeIt(name='')[source]

Bases: object

Context manager for timing the execution of a code block.

Classes:

Status(name[, elapse, has_ended, error])

Status of a single pg.timeit.

StatusSummary([breakdown])

Aggregated summary for repeated calls for pg.timeit.

Methods:

add(context)

Adds a child context.

end([error])

Ends timing.

start()

Starts timing.

status()

Gets the status of all timeit under this context.

Attributes:

children

Returns child contexts.

elapse

Returns the elapse since start until end.

end_time

Returns end time.

error

Returns error.

has_ended

Returns whether the context has ended.

has_error

Returns whether the context has error.

has_started

Returns whether the context has started.

name

Returns the name of the context.

start_time

Returns start time.

class Status(name, elapse=0.0, has_ended=True, error=None)[source]

Bases: pg.JSONConvertible

Status of a single pg.timeit.

Attributes:

has_error

Returns whether the context has error.

has_started

Returns whether the context has started.

Methods:

merge(other)

Merges the status of two pg.timeit.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

property has_error: bool

Returns whether the context has error.

property has_started: bool

Returns whether the context has started.

merge(other)

Merges the status of two pg.timeit.

Return type:

Status

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:
  • context – JSON conversion context.

  • **kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.

class StatusSummary(breakdown=<factory>)[source]

Bases: pg.JSONConvertible

Aggregated summary for repeated calls for pg.timeit.

Classes:

Entry([num_started, num_ended, num_failed, ...])

Aggregated status from the pg.timeit calls of the same name.

Methods:

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

class Entry(num_started=0, num_ended=0, num_failed=0, avg_duration=0.0, error_tags=<factory>)

Bases: pg.JSONConvertible

Aggregated status from the pg.timeit calls of the same name.

Methods:

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:
  • context – JSON conversion context.

  • **kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:
  • context – JSON conversion context.

  • **kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.

add(context)[source]

Adds a child context.

property children: List[TimeIt][source]

Returns child contexts.

property elapse: float[source]

Returns the elapse since start until end.

end(error=None)[source]

Ends timing.

Return type:

bool

property end_time: float | None[source]

Returns end time.

property error: ErrorInfo | None[source]

Returns error.

property has_ended: bool[source]

Returns whether the context has ended.

property has_error: bool[source]

Returns whether the context has error.

property has_started: bool[source]

Returns whether the context has started.

property name: str[source]

Returns the name of the context.

start()[source]

Starts timing.

property start_time: float | None[source]

Returns start time.

status()[source]

Gets the status of all timeit under this context.

Return type:

Dict[str, Status]