Compute Time Between Points#

Synopsis#

Compute the time between points in code. The Report() method is available in ITK 4.9.0 or later.

Results#

Mean: 0.00756311416626
Total: 0.00756311416626
Mean: 0.00671458244324
Total: 0.0134291648865
System:              clay
Processor:           Unknown P6 family
    Cache:           15360
    Clock:           2194.87
    Cores:           12 cpus x 12 Cores = 144
    Virtual Memory:  Total: 0 Available: 0
    Physical Memory: Total:64294 Available: 36172
OSName:              Linux
    Release:         4.1.4-calculate
    Version:         #2 SMP PREEMPT Sun Aug 9 17:03:44 EDT 2015
    Platform:        x86_64
    Operating System is 64 bit
ITK Version: 4.9.0
Name Of Probe(Time)           Iteration      Total(s)       Min(s)         Mean(s)        Max(s)         Std(s)
                              2              0.0134292      0.00586605     0.00671458     0.00756311     0.00120001

Code#

C++#

#include "itkTimeProbe.h"
#include "itkNumericTraits.h"

#include <iostream>
#include <string>

void
LongFunction()
{
  for (int i = 0; i < itk::NumericTraits<int>::max() / 100; ++i)
  {
    double a = 0;
    (void)a;
  }
}

int
main()
{
  itk::TimeProbe clock;

  clock.Start();
  LongFunction();

  clock.Stop();
  std::cout << "Mean: " << clock.GetMean() << std::endl;
  std::cout << "Total: " << clock.GetTotal() << std::endl;

  clock.Start();
  LongFunction();

  clock.Stop();
  std::cout << "Mean: " << clock.GetMean() << std::endl;
  std::cout << "Total: " << clock.GetTotal() << std::endl;

  clock.Report();

  return EXIT_SUCCESS;
}

Python#

#!/usr/bin/env python

import itk


def LongFunction():
    # CPython loops are much slower than C++,
    # so a smaller range is used in this case.
    for i in range(int(1e5)):
        a = 0.0  # noqa: F841


clock = itk.TimeProbe()

clock.Start()
LongFunction()

clock.Stop()
print("Mean: " + str(clock.GetMean()))
print("Total: " + str(clock.GetTotal()))

clock.Start()
LongFunction()

clock.Stop()
print("Mean: " + str(clock.GetMean()))
print("Total: " + str(clock.GetTotal()))

clock.Report()

Classes demonstrated#

class TimeProbe : public itk::ResourceProbe<RealTimeClock::TimeStampType, RealTimeClock::TimeStampType>

Computes the time passed between two points in code.

This class allows the user to trace the time passed between the execution of two pieces of code. It can be started and stopped in order to evaluate the execution over multiple passes. The values of time are taken from the RealTimeClock.

See

RealTimeClock

ITK Sphinx Examples:

See itk::TimeProbe for additional documentation.