CmpStr - v3.3.0
    Preparing search index...

    Profiler class for measuring execution time and memory usage of functions.

    Index

    Constructors

    • Private constructor to enforce singleton pattern. Initializes the store for profiler entries.

      Parameters

      • Optionalactive: boolean = false

        Optional parameter to enable the profiler

      Returns Profiler

    Properties

    active: boolean = false

    Optional parameter to enable the profiler

    last?: ProfilerEntry<any>
    memFn: () => number
    nowFn: () => number

    Pre-computed functions for time and memory retrieval

    services: ProfilerService<any> = ...

    Returns the services provided by the Profiler class. This allows for easy access to the profiler's methods.

    • An object containing methods to control the profiler
    store: ProfilerEntry<any>[] = []

    Store for profiler entries

    totalMem: number = 0
    totalTime: number = 0

    Total time and memory consumption

    ENV: "unknown" | "browser" | "nodejs"

    Environment detection

    instance: Profiler

    Singleton instance

    Methods

    • Resets the profiler by clearing the store, total time and memory consumption. This method is useful for starting a new profiling session.

      Returns void

    • Disables the profiler. Sets the active state to false, preventing further profiling.

      Returns void

    • Enables the profiler. Sets the active state to true, allowing profiling to occur.

      Returns void

    • Retrieves the total time and memory consumption recorded by the profiler.

      Returns { mem: number; time: number }

      • An object containing total time and memory usage
    • Runs a synchronous function and profiles its execution time and memory usage. If the profiler is not active, it simply executes the function without profiling.

      Type Parameters

      • T

      Parameters

      • fn: () => T

        Function to be executed and profiled

      • meta: Record<string, any> = {}

        Metadata to be associated with the profiling entry

      Returns T

      • The result of the executed function
    • Runs an asynchronous function and profiles its execution time and memory usage. If the profiler is not active, it simply executes the function without profiling.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        Asynchronous function to be executed and profiled

      • meta: Record<string, any> = {}

        Metadata to be associated with the profiling entry

      Returns Promise<T>

      • A promise that resolves to the result of the executed function
    • Stores a profiler entry in the store and updates the total time and memory consumption.

      Type Parameters

      • T

      Parameters

      Returns void

    • Sets the environment based on the available global objects. Detects if running in Node.js or browser and sets the ENV property accordingly.

      Returns void

    • Returns the singleton instance of the Profiler class. If the instance does not exist, it creates a new one.

      Parameters

      • Optionalenable: boolean

        Optional parameter to enable the profiler upon instantiation

      Returns Profiler

      • Singleton Profiler instance