Skip to main content
Log in

Mojo struct

ProfileBlock

struct ProfileBlock[enabled: Bool = False]

A struct for profiling code blocks.

This struct provides context manager functionality to profile code blocks. When enabled, it records the start and end time of the block and prints the timing information.

Parameters

  • enabled (Bool): Whether profiling is enabled for this block.

Fields

  • name (StringLiteral):
  • loc (_SourceLocation):
  • start_time (UInt):

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

__init__

@implicit __init__(out self, name: StringLiteral)

Initialize a new ProfileBlock.

Args:

  • name (StringLiteral): Name to identify this profiling block.

__enter__

__enter__(mut self)

Enter the profiling block and record start time if enabled.

__exit__

__exit__(mut self)

Exit the profiling block, record end time and print timing if enabled.