Tapkee
time.hpp
Go to the documentation of this file.
00001 /* This software is distributed under BSD 3-clause license (see LICENSE file).
00002  *
00003  * Copyright (c) 2012-2013 Sergey Lisitsyn
00004  */
00005 
00006 #ifndef TAPKEE_TIME_H_
00007 #define TAPKEE_TIME_H_
00008 
00009 /* Tapkee includes */
00010 #include <tapkee/utils/logging.hpp>
00011 /* End of Tapkee includes */
00012 
00013 #include <ctime>
00014 #include <string>
00015 #include <sstream>
00016 
00017 namespace tapkee
00018 {
00019 namespace tapkee_internal
00020 {
00021 #ifdef _OPENMP
00022     #define CLOCK_TYPE double
00023     #define CLOCK_GET omp_get_wtime()
00024     #define CLOCK_DIVISOR 1
00025 #else
00026     #define CLOCK_TYPE clock_t
00027     #define CLOCK_GET clock()
00028     #define CLOCK_DIVISOR CLOCKS_PER_SEC
00029 #endif
00030 
00031 struct timed_context
00032 {
00033     CLOCK_TYPE start_clock;
00034     std::string operation_name;
00035     timed_context(const std::string& name) : start_clock(CLOCK_GET), operation_name(name)
00036     {
00037     }
00038     ~timed_context()
00039     {
00040         std::stringstream msg_stream;
00041         msg_stream << operation_name << " took " << double(CLOCK_GET-start_clock)/CLOCK_DIVISOR << " seconds."; 
00042         LoggingSingleton::instance().message_benchmark(msg_stream.str());
00043     }
00044 };
00045 }
00046 }
00047 
00048 #undef CLOCK_TYPE
00049 #undef CLOCK_GET
00050 #undef CLOCK_DIVISOR
00051 
00052 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines