Skip to content

Commit 6c587c0

Browse files
committed
benchmarks
1 parent 9ab7532 commit 6c587c0

File tree

5 files changed

+45377
-3
lines changed

5 files changed

+45377
-3
lines changed

CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ add_executable(delaunator-test src/delaunator-test.cpp)
1919
target_link_libraries(delaunator-test delaunator)
2020
target_include_directories (delaunator-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/catch/single_include/catch2")
2121
target_link_libraries(delaunator-test json-helpers)
22-
target_link_libraries(delaunator-test delaunator)
22+
23+
#benchmark
24+
add_executable(benchmark src/benchmark.cpp)
25+
target_link_libraries(benchmark delaunator)
26+
target_link_libraries(benchmark json-helpers)
2327

2428

2529
#triangulate

generate-reference-triangles/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ for(let i = 0; i < n; i++) {
1818
coords[2 * i + 1] = f.geometry.coordinates[1];
1919
}
2020

21-
console.time('Delaunator');
21+
const start = Date.now();
2222
const delaunator = new Delaunator(coords);
23-
console.timeEnd('Delaunator');
23+
const end = Date.now();
24+
25+
console.log('points =', coords.length / 2);
26+
console.log('miliseconds =', end - start);
27+
console.log('triangles =', delaunator.triangles.length);
2428

2529
const trianglesAr = Array.from(delaunator.triangles);
2630
writeFileSync(outputFile, JSON.stringify(trianglesAr));

src/benchmark.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
#include <chrono>
3+
#include "delaunator.h"
4+
#include "json-helpers.h"
5+
#include <string>
6+
#include <vector>
7+
8+
using namespace std;
9+
int main(int, char* argv[]) {
10+
string points_str = json_helpers::read_file("./test-files/osm-nodes-45331-epsg-3857.geojson");
11+
const vector<double> coords = json_helpers::get_geo_json_points(points_str);
12+
13+
auto t_start = chrono::high_resolution_clock::now();
14+
Delaunator delaunator(move(coords));
15+
auto t_end = chrono::high_resolution_clock::now();
16+
17+
auto milliseconds = chrono::duration_cast<chrono::milliseconds>(t_end - t_start).count();
18+
19+
printf("coords=%lu \n", delaunator.coords.size() / 2);
20+
printf("milliseconds=%lld \n", milliseconds);
21+
printf("triangles=%lu \n", delaunator.triangles.size());
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)