Skip to content

Use lowest instead of min #28

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS})
include_directories("${PROJECT_SOURCE_DIR}/include")

file(GLOB TEST_SOURCES test/*.cpp)
set(TEST_SOURCES ${TEST_SOURCES} include/delaunator.cpp)
add_executable(unit-tests ${TEST_SOURCES})

file(GLOB TEST_SOURCES test-header-only/*.cpp)
add_executable(header-only-unit-tests ${TEST_SOURCES})

# libbenchmark.a supports threads and therefore needs pthread support
find_package(Threads REQUIRED)
file(GLOB BENCH_SOURCES bench/*.cpp)
set(BENCH_SOURCES ${BENCH_SOURCES} include/delaunator.cpp)
add_executable(bench-tests ${BENCH_SOURCES})
if(BENCHMARK_BIG_O)
message("-- BENCHMARK_BIG_O=1")
Expand All @@ -67,8 +72,8 @@ if(BENCHMARK_10M)
endif()

#examples
add_executable(triangulate-geojson examples/triangulate_geojson.cpp)
add_executable(basic examples/basic.cpp)
add_executable(triangulate-geojson examples/triangulate_geojson.cpp include/delaunator.cpp)
add_executable(basic examples/basic.cpp include/delaunator.cpp)


# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ xcode:
mkdir -p ./$(XCODE_PROJ_DIR) && cd ./$(XCODE_PROJ_DIR) && cmake -G Xcode ../

test:
@if [ -f ./$(BUILD_DIR)/unit-tests ]; then ./$(BUILD_DIR)/unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
@if [ -f ./$(BUILD_DIR)/unit-tests ]; then ./$(BUILD_DIR)/unit-tests; ./$(BUILD_DIR)/header-only-unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi

bench:
@if [ -f ./$(BUILD_DIR)/bench-tests ]; then ./$(BUILD_DIR)/bench-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
Expand Down Expand Up @@ -44,4 +44,4 @@ distclean: clean
format:
./scripts/format.sh

.PHONY: test bench
.PHONY: test bench
19 changes: 19 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool:
vmImage: 'ubuntu-latest'

steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'

- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
45 changes: 44 additions & 1 deletion bench/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <random>
#include <string>
#include <vector>
#include <iostream>

std::vector<double> generate_uniform(std::size_t n) {
std::vector<double> coords;
Expand All @@ -19,7 +20,7 @@ std::vector<double> generate_uniform(std::size_t n) {
}

void BM_45K_geojson_nodes(benchmark::State& state) {
std::string points_str = utils::read_file("./test/test-files/osm-nodes-45331-epsg-3857.geojson");
std::string points_str = utils::read_file("./test-files/osm-nodes-45331-epsg-3857.geojson");
std::vector<double> coords = utils::get_geo_json_points(points_str);

while (state.KeepRunning()) {
Expand All @@ -35,6 +36,48 @@ void BM_uniform(benchmark::State& state) {
state.SetComplexityN(state.range(0));
}

class MyFixture : public ::benchmark::Fixture
{
public:
MyFixture() : vals(generate_uniform(10000000))
{
}

virtual void SetUp(::benchmark::State&)
{}

virtual void TearDown(::benchmark::State&)
{}

std::vector<double> vals;
};

/**
BENCHMARK_DEFINE_F(MyFixture, minmax)(::benchmark::State&state)
{
std::cerr << "vals size = " << vals.size() << "!\n";
double mn = std::numeric_limits<double>::max();
double mx = std::numeric_limits<double>::lowest();
while (state.KeepRunning())
{
for (int i = 0; i < 100; ++i)
{
for (double& v : vals)
{
mn = std::min(mn, v);
mx = std::max(mx, v);
if (v < mn)
mn = v;
if (v > mx)
mx = v;
}
}
}
std::cerr << "MIN/MAX = " << mn << "/" << mx << "!\n";
}
BENCHMARK_REGISTER_F(MyFixture, minmax)->Unit(benchmark::kMillisecond);
**/

BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_uniform)->Arg(2000)->Arg(100000)->Arg(200000)->Arg(500000)->Arg(1000000)->Unit(benchmark::kMillisecond);

Expand Down
27 changes: 27 additions & 0 deletions bench_results
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Debug:

Run on (8 X 2600 MHz CPU s)
2019-11-14 09:43:59
------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------
BM_45K_geojson_nodes 94 ms 94 ms 7
BM_uniform/2000 3 ms 3 ms 213
BM_uniform/100000 232 ms 231 ms 3
BM_uniform/200000 517 ms 517 ms 1
BM_uniform/500000 1429 ms 1427 ms 1
BM_uniform/1000000 3084 ms 3081 ms 1

Release:

Run on (8 X 2600 MHz CPU s)
2019-11-14 09:46:33
------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------
BM_45K_geojson_nodes 23 ms 23 ms 31
BM_uniform/2000 1 ms 1 ms 1010
BM_uniform/100000 65 ms 64 ms 10
BM_uniform/200000 158 ms 157 ms 4
BM_uniform/500000 449 ms 448 ms 2
BM_uniform/1000000 1075 ms 1074 ms 1
9 changes: 9 additions & 0 deletions include/delaunator-header-only.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#define DELAUNATOR_HEADER_ONLY

#include "delaunator.hpp"

#include "delaunator.cpp"

#undef DELAUNATOR_HEADER_ONLY
Loading