Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++11 std::chrono for Profiler #193

Merged
merged 3 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions benchmarks/algorithm/VoronoiPerfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,34 @@ class VoronoiPerfTest {
}
private:
decltype(geos::geom::GeometryFactory::create()) gfact = geos::geom::GeometryFactory::create();
geos::util::Profiler* profiler = geos::util::Profiler::instance();

template<typename T>
void voronoi(const T & sites) {
geos::util::Profile sw(std::string("Voronoi from ") + typeid(T).name());
sw.start();
auto sw = profiler->get(std::string("Voronoi from ") + typeid(T).name());
sw->start();

geos::triangulate::VoronoiDiagramBuilder vdb;
vdb.setSites(sites);

auto result = vdb.getDiagram(*gfact);
sw.stop();

std::cout << sw.name << ": " << result->getNumGeometries() << ": " << sw.getTotFormatted() << std::endl;
sw->stop();
std::cout << sw->name << ": " << result->getNumGeometries() << ": " << *sw << std::endl;
}

template<typename T>
void delaunay(const T & seq) {
geos::util::Profile sw(std::string("Delaunay from ") + typeid(T).name());
sw.start();
auto sw = profiler->get(std::string("Delaunay from ") + typeid(T).name());
sw->start();

geos::triangulate::DelaunayTriangulationBuilder dtb;
dtb.setSites(seq);

auto result = dtb.getTriangles(*gfact);

sw.stop();
std::cout << sw.name << ": " << result->getNumGeometries() << ": " << sw.getTotFormatted() << std::endl;
sw->stop();
std::cout << sw->name << ": " << result->getNumGeometries() << ": " << *sw << std::endl;
}
};

Expand Down
1 change: 0 additions & 1 deletion include/geos/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ geos_HEADERS = \
precision.h \
profiler.h \
spatialIndex.h \
timeval.h \
unload.h \
util.h

Expand Down
59 changes: 19 additions & 40 deletions include/geos/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,8 @@
#ifndef GEOS_PROFILER_H
#define GEOS_PROFILER_H

#include <stdlib.h> /** need this to correctly detect MINGW64 **/
#include <geos/export.h>

/* For MingW builds with __STRICT_ANSI__ (-ansi) */
/** MINGW64 doesn't have a config.h **/
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
/* Allow us to check for presence of gettimeofday in MingW */
#include <config.h>

#include <sys/time.h>
extern "C" {
extern _CRTIMP void __cdecl _tzset(void);
__MINGW_IMPORT int _daylight;
__MINGW_IMPORT long _timezone;
__MINGW_IMPORT char* _tzname[2];
}
#endif

#if defined(_MSC_VER) || defined(__MINGW32__) && !defined(HAVE_GETTIMEOFDAY) && !defined(__MINGW64_VERSION_MAJOR)
#include <geos/timeval.h>
#else
#include <sys/time.h>
#endif
#include <chrono>

#include <map>
#include <memory>
Expand Down Expand Up @@ -65,29 +44,30 @@ namespace util {
*/
class GEOS_DLL Profile {
public:
using timeunit = std::chrono::microseconds;

/** \brief Create a named profile */
Profile(std::string name);

/** \brief Destructor */
~Profile();
~Profile() = default;

/** \brief start a new timer */
void
start()
{
gettimeofday(&starttime, nullptr);
starttime = std::chrono::high_resolution_clock::now();
}

/** \brief stop current timer */
void
stop()
{
gettimeofday(&stoptime, nullptr);
double elapsed = static_cast<double>(
1000000 * (stoptime.tv_sec - starttime.tv_sec)
+ (stoptime.tv_usec - starttime.tv_usec));
stoptime = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<timeunit>(stoptime - starttime);

timings.push_back(elapsed);

totaltime += elapsed;
if(timings.size() == 1) {
max = min = elapsed;
Expand All @@ -100,7 +80,8 @@ class GEOS_DLL Profile {
min = elapsed;
}
}
avg = totaltime / static_cast<double>(timings.size());

avg = static_cast<double>(totaltime.count()) / static_cast<double>(timings.size());
}

/** \brief Return Max stored timing */
Expand All @@ -126,25 +107,23 @@ class GEOS_DLL Profile {


private:

/* \brief current start and stop times */
struct timeval starttime, stoptime;
std::chrono::high_resolution_clock::time_point starttime, stoptime;

/* \brief actual times */
std::vector<double> timings;
std::vector<timeunit> timings;

/* \brief total time */
double totaltime;
timeunit totaltime;

/* \brief max time */
double max;
timeunit max;

/* \brief max time */
double min;
timeunit min;

/* \brief max time */
/* \brief avg time */
double avg;

};

/*
Expand All @@ -157,8 +136,8 @@ class GEOS_DLL Profiler {

public:

Profiler();
~Profiler();
Profiler() = default;
~Profiler() = default;

/**
* \brief
Expand All @@ -184,7 +163,7 @@ class GEOS_DLL Profiler {
/** \brief get Profile of named task */
Profile* get(std::string name);

std::map<std::string, Profile*> profs;
std::map<std::string, std::unique_ptr<Profile>> profs;
};


Expand Down
130 changes: 0 additions & 130 deletions include/geos/timeval.h

This file was deleted.

Loading