[Insight-users] visual c++ question: how can I read the current time of my computer?

Luis Ibanez luis.ibanez@kitware.com
Mon, 21 Oct 2002 10:57:19 -0400


Hi Zein,


A) The short answer:


    use the function  :   clock()
    it requires       :   #include <time.h>

    Note that the precision is different on
    Windows and Unix machines.  Windows only
    returns miliseconds with this funcion.

    You may want to run your algorithm
    several times and get mean times.
    (that's what itk::TimeProbe's do...)



B) The long (and better) answer:


ITK has a set of classes designed for algorithm timing.

You can find them in:     Insight/Code/Common

They are:

       itk::TimeProbe
       itk::TimeProbesCollectorBase

http://www.itk.org/Insight/Doxygen/html/classitk_1_1TimeProbe.html
http://www.itk.org/Insight/Doxygen/html/classitk_1_1TimeProbesCollectorBase.html

Here is how you can use it:

    itk::TimeProbe  myprobe;

    myprobe.Start();
    myAlgorithm->Run()
    myprobe.Stop();

    std::cout << myprobe.GetMeanTime() << std::endl;

============

Note that the probe has Start() and Stop() methods
that facilitates to compute mean times by running
your algorithm in a loop.

like

   for(int i=0; i<1000; i++)
     {
     myprobe.Start();
     myalgorithm->Run();
     myprobe.Stop();
     }

   std::cout << myprobe.GetMeanTime() << std::endl;

=====================

The TimeCollectorBase is a helper class that facilitates
to create multiple TimeProbes on the fly. TimeProbes are
kept in a std::map<> indexed by a name.


The collector is used like:

   itk::TimeProbesCollectorBase  timeCollector;

   timeCollector.Start("myFirstAlgorithm");
   firstAlgorithm->Run();
   timeCollector.Stop("myFirstAlgorithm");

   timeCollector.Start("mySecondAlgorithm");
   secondAlgorithm->Run();
   timeCollector.Stop("mySecondlgorithm");

   timeCollector.Report();


3) In addition to that, there is a FLTK GUI module
    for the timeProbesCollector.  It can be found in

         Insight/Auxiliary/FltkImageViewer

    It is used in the ThinPlateSplines example for
    timing differences between VTK and ITK
    implementations of thin kernel based interpolators.




Please let us know if you have further questions,


    Thanks


     Luis


===============================================

Zein Salah wrote:
> Hallo Friends,
> 
>  
> 
> how can I read the current time of my computer? I use visual c++
> 
> I need this to determine hoe long does an algorithm work, so other 
> solutions are also appreciated.
> 
>  
> 
> many thanks,
> 
> zein
> 
>  
> 
>  
> 
> ->8<------------->8<------------->8<------------->8<------------->8<------------->8<-
> Zein I. Salah
> Universität Tübingen, WSI-GRIS
> Sand 14
> 72076 Tübingen
> Email: salah@gris.uni-tuebingen.de <mailto:salah@gris.uni-tuebingen.de>  
> / zeinsalah@hotmail.com <mailto:zeinsalah@hotmail.com>
> Tel.: (07071) 29 75465 (GRIS) , (07071) 96 44 39 (privat)
> Fax: (07071) 29 54 66
>