D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Tue Aug 10 19:14:16 2010

# std.perf

Platform-independent performance measurement and timing classes.

PerformanceCounter is the main platform-independent timer class provided, covering the most typical use case, measuring elapsed wall-clock time.

The module also provides several Windows-specific timers that can be useful in specialized situations.

Synopsis:

    alias PerformanceCounter.interval_t interval_t;
    auto timer = new PerformanceCounter;
    timer.start();
    // do computation
    timer.stop();
    interval_t elapsedMsec = timer.milliseconds;
    writefln("Time elapsed: %s msec", elapsedMsec);

In particular note that stop() must be called before querying the elapsed time.

These classes were ported to D from the STLSoft C++ libraries, which were documented in the article " Win32 Performance Measurement Options", May 2003 issue of Windows Develper Network.

Author:
Matthew Wilson

class PerformanceCounter;
  A performance counter that uses the most accurate measurement APIs available on the host machine

  On Linux, the implementation uses gettimeofday(). For Windows, QueryPerformanceCounter() is used if available, GetTickCount() otherwise.

  alias interval_t;
    The type of the interval measurement (generally a 64-bit signed integer)

  void start();
    Starts measurement

    Begins a measurement period

  void stop();
    Ends measurement

    Marks the end of a measurement period. This must be called before querying the elapsed time with period_count, seconds, milliseconds, or microseconds.

    The stop() method may be called multiple times without an intervening start(). Elapsed time is always measured from most recent start() to the most recent stop().

  const interval_t periodCount();
    The elapsed count in the measurement period

    This represents the extent, in machine-specific increments, of the measurement period

  const interval_t seconds();
    The number of whole seconds in the measurement period

    This represents the extent, in whole seconds, of the measurement period

  const interval_t milliseconds();
    The number of whole milliseconds in the measurement period

    This represents the extent, in whole milliseconds, of the measurement period

  const interval_t microseconds();
    The number of whole microseconds in the measurement period

    This represents the extent, in whole microseconds, of the measurement period

class TickCounter;
  A low-cost, low-resolution performance counter

  This class provides low-resolution, but low-latency, performance monitoring.

  This class is available only on Windows, but is guaranteed to be meaningful on all Windows operating systems.

  alias interval_t;
    The interval type

    The type of the interval measurement (generally a 64-bit signed integer)

  void start();
    Starts measurement

    Begins a measurement period

  void stop();
    Ends measurement

    Marks the end of a measurement period. This must be called before querying the elapsed time with period_count, seconds, milliseconds, or microseconds.

    The stop() method may be called multiple times without an intervening start(). Elapsed time is always measured from most recent start() to the most recent stop().

  const interval_t periodCount();
    The elapsed count in the measurement period

    This represents the extent, in machine-specific increments, of the measurement period

  const interval_t seconds();
    The number of whole seconds in the measurement period

    This represents the extent, in whole seconds, of the measurement period

  const interval_t milliseconds();
    The number of whole milliseconds in the measurement period

    This represents the extent, in whole milliseconds, of the measurement period

  const interval_t microseconds();
    The number of whole microseconds in the measurement period

    This represents the extent, in whole microseconds, of the measurement period

class ThreadTimesCounter;
  A performance counter that provides thread-specific performance timings

  This class uses the operating system's performance monitoring facilities to provide timing information pertaining to the calling thread only, irrespective of the activities of other threads on the system. This class does not provide meaningful timing information on operating systems that do not provide thread-specific monitoring.

  This class is available only on Windows.

  alias interval_t;
    The interval type

    The type of the interval measurement (generally a 64-bit signed integer)

  this();
    Constructor

    Creates an instance of the class, and caches the thread token so that measurements will be taken with respect to the thread in which the class was created.

  void start();
    Starts measurement

    Begins a measurement period

  void stop();
    Ends measurement

    Marks the end of a measurement period. This must be called before querying the elapsed time with period_count, seconds, milliseconds, or microseconds.

    The stop() method may be called multiple times without an intervening start(). Elapsed time is always measured from most recent start() to the most recent stop().

  const interval_t kernelPeriodCount();
    The elapsed count in the measurement period for kernel mode activity

    This represents the extent, in machine-specific increments, of the measurement period for kernel mode activity

  const interval_t kernelSeconds();
    The number of whole seconds in the measurement period for kernel mode activity

    This represents the extent, in whole seconds, of the measurement period for kernel mode activity

  const interval_t kernelMilliseconds();
    The number of whole milliseconds in the measurement period for kernel mode activity

    This represents the extent, in whole milliseconds, of the measurement period for kernel mode activity

  const interval_t kernelMicroseconds();
    The number of whole microseconds in the measurement period for kernel mode activity

    This represents the extent, in whole microseconds, of the measurement period for kernel mode activity

  const interval_t userPeriodCount();
    The elapsed count in the measurement period for user mode activity

    This represents the extent, in machine-specific increments, of the measurement period for user mode activity

  const interval_t userSeconds();
    The number of whole seconds in the measurement period for user mode activity

    This represents the extent, in whole seconds, of the measurement period for user mode activity

  const interval_t userMilliseconds();
    The number of whole milliseconds in the measurement period for user mode activity

    This represents the extent, in whole milliseconds, of the measurement period for user mode activity

  const interval_t userMicroseconds();
    The number of whole microseconds in the measurement period for user mode activity

    This represents the extent, in whole microseconds, of the measurement period for user mode activity

  const interval_t periodCount();
    The elapsed count in the measurement period

    This represents the extent, in machine-specific increments, of the measurement period

  const interval_t seconds();
    The number of whole seconds in the measurement period

    This represents the extent, in whole seconds, of the measurement period

  const interval_t milliseconds();
    The number of whole milliseconds in the measurement period

    This represents the extent, in whole milliseconds, of the measurement period

  const interval_t microseconds();
    The number of whole microseconds in the measurement period

    This represents the extent, in whole microseconds, of the measurement period

class ProcessTimesCounter;
  A performance counter that provides process-specific performance timings

  This class uses the operating system's performance monitoring facilities to provide timing information pertaining to the calling process only, irrespective of the activities of other processes on the system. This class does not provide meaningful timing information on operating systems that do not provide process-specific monitoring.

  This class is available only on Windows.

  alias interval_t;
    The interval type

    The type of the interval measurement (generally a 64-bit signed integer)

  void start();
    Starts measurement

    Begins a measurement period

  void stop();
    Ends measurement

    Marks the end of a measurement period. This must be called before querying the elapsed time with period_count, seconds, milliseconds, or microseconds.

    The stop() method may be called multiple times without an intervening start(). Elapsed time is always measured from most recent start() to the most recent stop().

  const interval_t kernelPeriodCount();
    The elapsed count in the measurement period for kernel mode activity

    This represents the extent, in machine-specific increments, of the measurement period for kernel mode activity

  const interval_t kernelSeconds();
    The number of whole seconds in the measurement period for kernel mode activity

    This represents the extent, in whole seconds, of the measurement period for kernel mode activity

  const interval_t kernelMilliseconds();
    The number of whole milliseconds in the measurement period for kernel mode activity

    This represents the extent, in whole milliseconds, of the measurement period for kernel mode activity

  const interval_t kernelMicroseconds();
    The number of whole microseconds in the measurement period for kernel mode activity

    This represents the extent, in whole microseconds, of the measurement period for kernel mode activity

  const interval_t userPeriodCount();
    The elapsed count in the measurement period for user mode activity

    This represents the extent, in machine-specific increments, of the measurement period for user mode activity

  const interval_t userSeconds();
    The number of whole seconds in the measurement period for user mode activity

    This represents the extent, in whole seconds, of the measurement period for user mode activity

  const interval_t userMilliseconds();
    The number of whole milliseconds in the measurement period for user mode activity

    This represents the extent, in whole milliseconds, of the measurement period for user mode activity

  const interval_t userMicroseconds();
    The number of whole microseconds in the measurement period for user mode activity

    This represents the extent, in whole microseconds, of the measurement period for user mode activity

  const interval_t periodCount();
    The elapsed count in the measurement period

    This represents the extent, in machine-specific increments, of the measurement period

  const interval_t seconds();
    The number of whole seconds in the measurement period

    This represents the extent, in whole seconds, of the measurement period

  const interval_t milliseconds();
    The number of whole milliseconds in the measurement period

    This represents the extent, in whole milliseconds, of the measurement period

  const interval_t microseconds();
    The number of whole microseconds in the measurement period

    This represents the extent, in whole microseconds, of the measurement period

Copyright © 1999-2010 by Digital Mars, All Rights Reserved | Page generated by Ddoc.