[geos-commits] [SCM] GEOS branch master updated. 2da5dc33519659272f86197751e4f0aa8656290b
git at osgeo.org
git at osgeo.org
Sat Jun 8 18:23:47 PDT 2019
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, master has been updated
via 2da5dc33519659272f86197751e4f0aa8656290b (commit)
via 44d77a23c63f9b532d84d4d8e516130f9ad12051 (commit)
via 4aeef3b90c4cce0d2747ab8081ca2cac0e4cd187 (commit)
via 72404597eb2cdce65f844feea0389040554fa985 (commit)
from dfb77838cfe82098d41106efaaf232657e604553 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2da5dc33519659272f86197751e4f0aa8656290b
Merge: dfb7783 44d77a2
Author: Daniel Baston <dbaston at gmail.com>
Date: Sat Jun 8 21:23:33 2019 -0400
Merge branch 'cpp11-profiler'
commit 44d77a23c63f9b532d84d4d8e516130f9ad12051
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu Jun 6 22:13:55 2019 -0400
More informative timing output in VoronoiPerfTest
diff --git a/benchmarks/algorithm/VoronoiPerfTest.cpp b/benchmarks/algorithm/VoronoiPerfTest.cpp
index 9ab6789..df90128 100644
--- a/benchmarks/algorithm/VoronoiPerfTest.cpp
+++ b/benchmarks/algorithm/VoronoiPerfTest.cpp
@@ -49,33 +49,34 @@ public:
}
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;
}
};
commit 4aeef3b90c4cce0d2747ab8081ca2cac0e4cd187
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu Jun 6 22:13:00 2019 -0400
Remove manual memory management in Profiler
diff --git a/include/geos/profiler.h b/include/geos/profiler.h
index e50a9c9..c98e3b4 100644
--- a/include/geos/profiler.h
+++ b/include/geos/profiler.h
@@ -50,7 +50,7 @@ public:
Profile(std::string name);
/** \brief Destructor */
- ~Profile();
+ ~Profile() = default;
/** \brief start a new timer */
void
@@ -136,8 +136,8 @@ class GEOS_DLL Profiler {
public:
- Profiler();
- ~Profiler();
+ Profiler() = default;
+ ~Profiler() = default;
/**
* \brief
@@ -163,7 +163,7 @@ public:
/** \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;
};
diff --git a/src/util/Profiler.cpp b/src/util/Profiler.cpp
index 0208df2..4b65799 100644
--- a/src/util/Profiler.cpp
+++ b/src/util/Profiler.cpp
@@ -29,10 +29,6 @@ Profile::Profile(string newname) :
totaltime(timeunit::zero())
{}
-Profile::~Profile()
-{
-}
-
double
Profile::getMax() const
{
@@ -78,29 +74,17 @@ Profile::getNumTimings() const
return timings.size();
}
-Profiler::Profiler()
-{
-}
-
-Profiler::~Profiler()
-{
- map<string, Profile*>::const_iterator it;
- for(it = profs.begin(); it != profs.end(); ++it) {
- delete it->second;
- }
-}
-
void
Profiler::start(string name)
{
- Profile* prof = get(name);
+ auto prof = get(name);
prof->start();
}
void
Profiler::stop(string name)
{
- map<string, Profile*>::iterator iter = profs.find(name);
+ auto iter = profs.find(name);
if(iter == profs.end()) {
cerr << name << ": no such Profile started";
return;
@@ -111,16 +95,12 @@ Profiler::stop(string name)
Profile*
Profiler::get(string name)
{
- Profile* prof;
- map<string, Profile*>::iterator iter = profs.find(name);
- if(iter == profs.end()) {
- prof = new Profile(name);
- profs.insert(pair<string, Profile*>(name, prof));
- }
- else {
- prof = iter->second;
+ auto& prof = profs[name];
+ if (prof == nullptr) {
+ prof.reset(new Profile(name));
}
- return prof;
+
+ return prof.get();
}
Profiler*
@@ -144,9 +124,8 @@ operator<< (ostream& os, const Profile& prof)
ostream&
operator<< (ostream& os, const Profiler& prof)
{
- map<string, Profile*>::const_iterator it;
- for(it = prof.profs.begin(); it != prof.profs.end(); ++it) {
- os << *(it->second) << endl;
+ for(const auto& entry : prof.profs) {
+ os << *(entry.second) << endl;
}
return os;
}
commit 72404597eb2cdce65f844feea0389040554fa985
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu Jun 6 20:56:54 2019 -0400
Use C++11 std::chrono for Profiler
This avoids the need for compiler-specific tests and headers, and
anecdotally seems to provide more repeatable measurements.
diff --git a/include/geos/Makefile.am b/include/geos/Makefile.am
index 8fa3be0..cc55c4a 100644
--- a/include/geos/Makefile.am
+++ b/include/geos/Makefile.am
@@ -50,7 +50,6 @@ geos_HEADERS = \
precision.h \
profiler.h \
spatialIndex.h \
- timeval.h \
unload.h \
util.h
diff --git a/include/geos/profiler.h b/include/geos/profiler.h
index c447704..e50a9c9 100644
--- a/include/geos/profiler.h
+++ b/include/geos/profiler.h
@@ -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>
@@ -65,6 +44,8 @@ namespace util {
*/
class GEOS_DLL Profile {
public:
+ using timeunit = std::chrono::microseconds;
+
/** \brief Create a named profile */
Profile(std::string name);
@@ -75,19 +56,18 @@ public:
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;
@@ -100,7 +80,8 @@ public:
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 */
@@ -126,25 +107,23 @@ public:
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;
-
};
/*
diff --git a/include/geos/timeval.h b/include/geos/timeval.h
deleted file mode 100644
index 3ece94e..0000000
--- a/include/geos/timeval.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2006 Wu Yongwei
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- * Note: This code is in the public domain, see
- * http://wyw.dcweb.cn/time.htm
- *
- **********************************************************************/
-
-#ifndef GEOS_TIMEVAL_H
-#define GEOS_TIMEVAL_H
-
-#if !defined(_WIN32)
-#error This header is dedicated to Windows platform only
-#endif
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-
-#ifndef STRICT
-#define STRICT
-#endif
-
-#include <winsock2.h>
-#include <time.h>
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define EPOCHFILETIME (116444736000000000i64)
-#else
-#define EPOCHFILETIME (116444736000000000LL)
-#endif
-
-struct timezone {
- int tz_minuteswest; /* minutes W of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
-
-#if !defined(_WIN32_WCE)
-
-__inline int
-gettimeofday(struct timeval* tv, struct timezone* tz)
-{
- FILETIME ft;
- LARGE_INTEGER li;
- __int64 t;
- static int tzflag;
-
- if(tv) {
- GetSystemTimeAsFileTime(&ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- t = li.QuadPart; /* In 100-nanosecond intervals */
- t -= EPOCHFILETIME; /* Offset to the Epoch time */
- t /= 10; /* In microseconds */
- tv->tv_sec = (long)(t / 1000000);
- tv->tv_usec = (long)(t % 1000000);
- }
-
- if(tz) {
- if(!tzflag) {
- _tzset();
- tzflag++;
- }
- tz->tz_minuteswest = _timezone / 60;
- tz->tz_dsttime = _daylight;
- }
-
- return 0;
-}
-
-#else
-
-__inline int
-gettimeofday(struct timeval* tv, struct timezone* tz)
-{
- SYSTEMTIME st;
- FILETIME ft;
- LARGE_INTEGER li;
- TIME_ZONE_INFORMATION tzi;
- __int64 t;
- static int tzflag;
-
- if(tv) {
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- t = li.QuadPart; /* In 100-nanosecond intervals */
- t -= EPOCHFILETIME; /* Offset to the Epoch time */
- t /= 10; /* In microseconds */
- tv->tv_sec = (long)(t / 1000000);
- tv->tv_usec = (long)(t % 1000000);
- }
-
- if(tz) {
- GetTimeZoneInformation(&tzi);
-
- tz->tz_minuteswest = tzi.Bias;
- if(tzi.StandardDate.wMonth != 0) {
- tz->tz_minuteswest += tzi.StandardBias * 60;
- }
-
- if(tzi.DaylightDate.wMonth != 0) {
- tz->tz_dsttime = 1;
- }
- else {
- tz->tz_dsttime = 0;
- }
- }
-
- return 0;
-}
-
-#endif /* _WIN32_WCE */
-
-#endif /* GEOS_TIMEVAL_H */
diff --git a/src/util/Profiler.cpp b/src/util/Profiler.cpp
index 1ff532d..0208df2 100644
--- a/src/util/Profiler.cpp
+++ b/src/util/Profiler.cpp
@@ -16,6 +16,7 @@
#include <iostream>
#include <map>
#include <string>
+#include <sstream>
#include <utility>
using namespace std;
@@ -23,12 +24,10 @@ using namespace std;
namespace geos {
namespace util { // geos.util
-Profile::Profile(string newname)
-{
- name = newname;
- totaltime = 0;
- min = max = avg = 0;
-}
+Profile::Profile(string newname) :
+ name(newname),
+ totaltime(timeunit::zero())
+{}
Profile::~Profile()
{
@@ -37,13 +36,13 @@ Profile::~Profile()
double
Profile::getMax() const
{
- return max;
+ return static_cast<double>(max.count());
}
double
Profile::getMin() const
{
- return min;
+ return static_cast<double>(min.count());
}
double
@@ -55,14 +54,16 @@ Profile::getAvg() const
double
Profile::getTot() const
{
- return totaltime;
+ return static_cast<double>(totaltime.count());
}
std::string
Profile::getTotFormatted() const
{
- long usec = (long) totaltime;
- std::string fmt = to_string(usec);
+ std::stringstream usec;
+ usec << totaltime.count();
+
+ std::string fmt = usec.str();
int insertPosition = static_cast<int>(fmt.length()) - 3;
while (insertPosition > 0) {
fmt.insert(insertPosition, ",");
-----------------------------------------------------------------------
Summary of changes:
benchmarks/algorithm/VoronoiPerfTest.cpp | 17 ++--
include/geos/Makefile.am | 1 -
include/geos/profiler.h | 59 +++++---------
include/geos/timeval.h | 130 -------------------------------
src/util/Profiler.cpp | 62 +++++----------
5 files changed, 49 insertions(+), 220 deletions(-)
delete mode 100644 include/geos/timeval.h
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list