libStatGen Software  1
Performance.h
00001 /*
00002  * Copyright (c) 2009 Regents of the University of Michigan
00003  *
00004  * Permission is hereby granted, free of charge, to any person
00005  * obtaining a copy of this software and associated documentation
00006  * files (the "Software"), to deal in the Software without
00007  * restriction, including without limitation the rights to use,
00008  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the
00010  * Software is furnished to do so, subject to the following
00011  * conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be
00014  * included in all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00017  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00018  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00019  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00023  * OTHER DEALINGS IN THE SOFTWARE.
00024  */
00025 
00026 #ifndef _PERFORMANCE_H
00027 #define _PERFORMANCE_H
00028 
00029 #include <sys/time.h>
00030 #include <time.h>
00031 
00032 class Timing
00033 {
00034     timeval startInterval;
00035     timeval endInterval;
00036 public:
00037     Timing()
00038     {
00039         start();
00040     }
00041     void start();
00042     void end();
00043     double interval();
00044 };
00045 
00046 inline void Timing::start()
00047 {
00048     gettimeofday(&startInterval, NULL);
00049 }
00050 
00051 inline void Timing::end()
00052 {
00053     gettimeofday(&endInterval, NULL);
00054 }
00055 
00056 ///
00057 /// Return time interval between start() and end()
00058 /// @return elapsed time in seconds
00059 ///
00060 inline double Timing::interval()
00061 {
00062     return (endInterval.tv_sec + (endInterval.tv_usec/1000000.0)) -
00063            (startInterval.tv_sec + (startInterval.tv_usec/1000000.0));
00064 }
00065 
00066 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends