15 #ifndef GEOS_PROFILER_H
16 #define GEOS_PROFILER_H
19 #include <geos/export.h>
23 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
29 extern _CRTIMP
void __cdecl _tzset (
void);
30 __MINGW_IMPORT
int _daylight;
31 __MINGW_IMPORT
long _timezone;
32 __MINGW_IMPORT
char *_tzname[2];
36 #if defined(_MSC_VER) || defined(__MINGW32__) && !defined(HAVE_GETTIMEOFDAY) && !defined(__MINGW64_VERSION_MAJOR)
37 #include <geos/timeval.h>
54 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
66 class GEOS_DLL Profile {
69 Profile(std::string name);
76 gettimeofday(&starttime,
nullptr);
82 gettimeofday(&stoptime,
nullptr);
83 double elapsed =
static_cast<double>(
84 1000000 * (stoptime.tv_sec - starttime.tv_sec)
85 + (stoptime.tv_usec - starttime.tv_usec));
87 timings.push_back(elapsed);
89 if ( timings.size() == 1 ) max = min = elapsed;
92 if ( elapsed > max ) max = elapsed;
93 if ( elapsed < min ) min = elapsed;
95 avg = totaltime /
static_cast<double>(timings.size());
99 double getMax()
const;
102 double getMin()
const;
105 double getTot()
const;
108 double getAvg()
const;
111 size_t getNumTimings()
const;
120 struct timeval starttime, stoptime;
123 std::vector<double> timings;
145 class GEOS_DLL Profiler {
157 static Profiler *instance(
void);
164 void start(std::string name);
171 void stop(std::string name);
174 Profile *get(std::string name);
176 std::map<std::string, Profile *> profs;
181 GEOS_DLL std::ostream& operator<< (std::ostream& os,
const Profile&);
184 GEOS_DLL std::ostream& operator<< (std::ostream& os,
const Profiler&);
193 #endif // ndef GEOS_PROFILER_H