Skip to content

Commit

Permalink
Add generic perf test for unary operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Dec 6, 2019
1 parent 09bdf26 commit 1e7fc88
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmarks/capi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ target_link_libraries(perf_geospreparedcontains PRIVATE geos geos_c)

add_executable(perf_intersection IntersectionPerfTest.cpp)
target_link_libraries(perf_intersection PRIVATE geos geos_c)

add_executable(perf_unary UnaryOpPerfTest.cpp)
target_link_libraries(perf_unary PRIVATE geos geos_c)
80 changes: 80 additions & 0 deletions benchmarks/capi/UnaryOpPerfTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2019 Daniel Baston <[email protected]>
*
* 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.
*
**********************************************************************/

#include <geos/profiler.h>
#include <geos_c.h>

#include <fstream>
#include <iostream>
#include <sstream>

int main(int argc, char** argv) {
if (argc != 3 && argc != 4) {
std::cout << "perf_unary reads geometries from a WKT file and" << std::endl;
std::cout << "performs a unary operation on each. The number of" << std::endl;
std::cout << "geometries processed can be limited by specifying n." << std::endl;
std::cout << std::endl;
std::cout << "The following operations are supported:" << std::endl;
std::cout << "- valid" << std::endl;
std::cout << std::endl;
std::cout << "Usage: perf_unary [wktfile] [operation] [n]" << std::endl;
return 0;
}

initGEOS(nullptr, nullptr);

std::string fname{argv[1]};
std::string op{argv[2]};

long max_geoms;
if (argc == 4) {
max_geoms = std::atol(argv[3]);
std::cout << "Reading up to " << max_geoms << " geometries from " << fname << std::endl;
} else {
std::cout << "Reading geometries from " << fname << std::endl;
max_geoms = -1;
}

std::vector<GEOSGeometry*> geoms;

std::ifstream f(fname);
std::string line;
long i = 0;
while(std::getline(f, line) && (max_geoms < 0 || i < max_geoms)) {
auto g = GEOSGeomFromWKT(line.c_str());
if (g != nullptr) {
geoms.push_back(g);
i++;
}
}
f.close();

std::cout << "Read " << geoms.size() << " geometries." << std::endl;

geos::util::Profile sw(op);
sw.start();

if (op == "valid") {
for (const auto& g : geoms) {
GEOSisValid(g);
}
}

sw.stop();
std::cout << sw.getTotFormatted() << std::endl;

for (auto& g : geoms) {
GEOSGeom_destroy(g);
}
}

0 comments on commit 1e7fc88

Please sign in to comment.