bgdev.tools.performance

Evaluation Toolkit.

created

03/06/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

class Profiler(timer=True, stats=True, sort='tottime', depth=8)[source]

Bases: object

Create a python profiler to check for code usage.

Example

from bgdev.tools.performance import Profiler()

# use as an instanciated object
profiler = Profiler()
profiler.start()
>>> run python code
profiler.stop()

# use as a context manager
with Profiler(sort="tottime", depth=10) as profiler:
    >>> run code

# print stats
profiler.stats("cumulative", depth=10)
__enter__()[source]

Initialise the timer on __enter__.

__exit__(exc_type, exc_value, exc_traceback)[source]

Stop timer and display cProfiler stats.

__init__(timer=True, stats=True, sort='tottime', depth=8)[source]

Initialize self. See help(type(self)) for accurate signature.

static display_timer(timer, message='')[source]

Get execution time.

start()[source]

Enable the profiler.

stats(sort=None, depth=None)[source]

Print profiler’s stats.

Parameters
  • sort (str) – Sort the stats with given value.

  • depth (int) – Maximum entries to print from the stat table.

step(message=None, running=False)[source]

Display a timer step.

stop()[source]

Stop the profiler.

frames_per_second(iterations=3, start=1001, frames=100, viewports='viewport2', meshes_only=True, outfile=None)[source]

Evaluate the framePerSecond in the current scene.

Parameters
  • iterations (int) – Amount of time the timeline should run.

  • start (int) – Start frame.

  • frames (int) – The amount of frames to run.

  • viewports (list) – Select the viewports you want to evaluate on. Possible values are “legacy” and “viewport2”.

  • meshes_only (bool) – Hides everything but meshes in the viewport.

  • outfile (bool or str) – Save the output fps in the given txt file. If True is passed, query the current scene path and save the log next to it (Useful when benchmarking multiple scenes in a loop).

Returns

The evaluated frame per seconds as a float number.

Return type

float