-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbbfda3
commit da7e939
Showing
10 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#pragma once | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cassert> | ||
#include <chrono> | ||
#include "emst.h" | ||
using namespace std::chrono; | ||
|
||
double uniform() { | ||
return rand() * 1.0 / RAND_MAX; | ||
} | ||
|
||
template<size_t DIM> | ||
std::vector<Point<DIM>> generate_points_uniform(size_t num_points, double MAX = 100.0) { | ||
std::vector<Point<DIM>> points; | ||
for (size_t i = 0; i < num_points; i++) { | ||
Point<DIM> p; | ||
for (size_t k = 0; k < DIM; k++) { | ||
p[k] = (uniform() * 2.0 - 1.0) * MAX; | ||
} | ||
points.push_back(p); | ||
} | ||
return points; | ||
} | ||
|
||
template<size_t DIM> | ||
std::vector<Point<DIM>> generate_points_gauss(size_t num_points, double MAX = 100.0) { | ||
std::vector<Point<DIM>> points; | ||
for (size_t i = 0; i < num_points; i++) { | ||
Point<DIM> p; | ||
for (size_t k = 0; k < DIM; k++) { | ||
p[k] = sqrt(-2 * log(uniform())) * cos(2 * 3.141592 * uniform()) * MAX; | ||
} | ||
points.push_back(p); | ||
} | ||
return points; | ||
} | ||
|
||
struct BenchmarkResult { | ||
double answer; | ||
double time; | ||
}; | ||
|
||
template<typename EmstSolverType, size_t DIM> | ||
BenchmarkResult run_benchmark(const std::vector<Point<DIM>> & points, size_t samples = 1) { | ||
BenchmarkResult result; | ||
auto start = std::chrono::system_clock::now(); | ||
for (size_t i = 0; i < samples; i++) { | ||
EmstSolverType solver(points); | ||
result.answer = solver.get_total_length(); | ||
} | ||
auto end = std::chrono::system_clock::now(); | ||
|
||
std::chrono::duration<double> elapsed_seconds = end - start; | ||
result.time = elapsed_seconds.count() / samples; | ||
return result; | ||
} | ||
|
||
template<size_t DIM> | ||
void run_becnhmarks(const std::vector<Point<DIM>> & points, size_t samples, std::ostream & cout, std::string distribution = "none") { | ||
auto result_kd = run_benchmark<KdTreeSolver<DIM>, DIM>(points, samples); | ||
auto result_prim = (points.size() < 100000 ? run_benchmark<PrimSolver<DIM>, DIM>(points, samples / 50 + 1) : BenchmarkResult{ result_kd.answer, 0 }); | ||
|
||
assert(fabs(result_kd.answer / result_prim.answer - 1.0) < 1e-8); | ||
cout.precision(6); | ||
cout.setf(std::ios::fixed); | ||
cout << "kd-tree" << "," << DIM << "," << points.size() << "," << distribution << "," << result_kd.time << "\n"; | ||
cout << "prim" << "," << DIM << "," << points.size() << "," << distribution << "," << result_prim.time << "\n"; | ||
cout.flush(); | ||
} | ||
|
||
template<size_t DIM> | ||
void run_becnhmarks(std::ostream & cout) { | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(10), 100, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(50), 100, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(100), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(500), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(1000), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(5000), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(10000), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(50000), 1, cout, "uniform"); | ||
/*run_becnhmarks<DIM>(generate_points_uniform<DIM>(100000), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(1000000), 1, cout, "uniform"); | ||
run_becnhmarks<DIM>(generate_points_uniform<DIM>(10000000), 1, cout, "uniform");*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
kd-tree,10,50000,uniform,105.451598 | ||
prim,10,50000,uniform,46.172490 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
kd-tree,2,10,uniform,0.000008 | ||
prim,2,10,uniform,0.000002 | ||
kd-tree,2,50,uniform,0.000066 | ||
prim,2,50,uniform,0.000026 | ||
kd-tree,2,100,uniform,0.000232 | ||
prim,2,100,uniform,0.000140 | ||
kd-tree,2,500,uniform,0.001721 | ||
prim,2,500,uniform,0.002644 | ||
kd-tree,2,1000,uniform,0.003552 | ||
prim,2,1000,uniform,0.009590 | ||
kd-tree,2,5000,uniform,0.020224 | ||
prim,2,5000,uniform,0.252968 | ||
kd-tree,2,10,gauss,0.000006 | ||
prim,2,10,gauss,0.000001 | ||
kd-tree,2,50,gauss,0.000073 | ||
prim,2,50,gauss,0.000023 | ||
kd-tree,2,100,gauss,0.000200 | ||
prim,2,100,gauss,0.000106 | ||
kd-tree,2,500,gauss,0.001533 | ||
prim,2,500,gauss,0.002456 | ||
kd-tree,2,1000,gauss,0.003350 | ||
prim,2,1000,gauss,0.009634 | ||
kd-tree,2,5000,gauss,0.018823 | ||
prim,2,5000,gauss,0.258483 | ||
kd-tree,2,10000,uniform,0.055037 | ||
prim,2,10000,uniform,1.214838 | ||
kd-tree,2,50000,uniform,0.248771 | ||
prim,2,50000,uniform,29.941540 | ||
kd-tree,2,100000,uniform,0.474029 | ||
prim,2,100000,uniform,118.912122 | ||
kd-tree,2,1000000,uniform,6.050678 | ||
prim,2,1000000,uniform,0.000000 | ||
kd-tree,2,10000000,uniform,69.181657 | ||
prim,2,10000000,uniform,0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
kd-tree,20,10,uniform,0.000020 | ||
prim,20,10,uniform,0.000005 | ||
kd-tree,20,50,uniform,0.000621 | ||
prim,20,50,uniform,0.000076 | ||
kd-tree,20,100,uniform,0.002770 | ||
prim,20,100,uniform,0.000310 | ||
kd-tree,20,500,uniform,0.067044 | ||
prim,20,500,uniform,0.005408 | ||
kd-tree,20,1000,uniform,0.243301 | ||
prim,20,1000,uniform,0.020259 | ||
kd-tree,20,5000,uniform,11.102134 | ||
prim,20,5000,uniform,0.533273 | ||
kd-tree,20,10000,uniform,47.100806 | ||
prim,20,10000,uniform,2.325517 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
kd-tree,3,10,uniform,0.000010 | ||
prim,3,10,uniform,0.000002 | ||
kd-tree,3,50,uniform,0.000118 | ||
prim,3,50,uniform,0.000024 | ||
kd-tree,3,100,uniform,0.000359 | ||
prim,3,100,uniform,0.000107 | ||
kd-tree,3,500,uniform,0.003382 | ||
prim,3,500,uniform,0.002890 | ||
kd-tree,3,1000,uniform,0.006814 | ||
prim,3,1000,uniform,0.010001 | ||
kd-tree,3,5000,uniform,0.051790 | ||
prim,3,5000,uniform,0.281046 | ||
kd-tree,3,10000,uniform,0.110697 | ||
prim,3,10000,uniform,1.263761 | ||
kd-tree,3,50000,uniform,0.676556 | ||
prim,3,50000,uniform,32.236291 | ||
kd-tree,3,100000,uniform,1.322128 | ||
prim,3,100000,uniform,129.617489 | ||
kd-tree,3,1000000,uniform,16.640953 | ||
prim,3,1000000,uniform,0.000000 | ||
kd-tree,3,10000000,uniform,186.681225 | ||
prim,3,10000000,uniform,0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
kd-tree,4,10,uniform,0.000009 | ||
prim,4,10,uniform,0.000003 | ||
kd-tree,4,50,uniform,0.000206 | ||
prim,4,50,uniform,0.000031 | ||
kd-tree,4,100,uniform,0.000642 | ||
prim,4,100,uniform,0.000145 | ||
kd-tree,4,500,uniform,0.007234 | ||
prim,4,500,uniform,0.002741 | ||
kd-tree,4,1000,uniform,0.015581 | ||
prim,4,1000,uniform,0.013089 | ||
kd-tree,4,5000,uniform,0.120508 | ||
prim,4,5000,uniform,0.321342 | ||
kd-tree,4,10000,uniform,0.274742 | ||
prim,4,10000,uniform,1.330939 | ||
kd-tree,4,50000,uniform,1.599925 | ||
prim,4,50000,uniform,36.231665 | ||
kd-tree,4,100000,uniform,3.741252 | ||
prim,4,100000,uniform,0.000000 | ||
kd-tree,4,1000000,uniform,54.396733 | ||
prim,4,1000000,uniform,0.000000 | ||
kd-tree,4,10000000,uniform,673.999727 | ||
prim,4,10000000,uniform,0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
kd-tree,5,10,uniform,0.000012 | ||
prim,5,10,uniform,0.000003 | ||
kd-tree,5,50,uniform,0.000273 | ||
prim,5,50,uniform,0.000030 | ||
kd-tree,5,100,uniform,0.001298 | ||
prim,5,100,uniform,0.000210 | ||
kd-tree,5,500,uniform,0.010577 | ||
prim,5,500,uniform,0.002901 | ||
kd-tree,5,1000,uniform,0.028380 | ||
prim,5,1000,uniform,0.012231 | ||
kd-tree,5,5000,uniform,0.210629 | ||
prim,5,5000,uniform,0.302468 | ||
kd-tree,5,10000,uniform,0.572781 | ||
prim,5,10000,uniform,0.000000 | ||
kd-tree,5,50000,uniform,3.905315 | ||
prim,5,50000,uniform,0.000000 | ||
kd-tree,5,100000,uniform,9.507483 | ||
prim,5,100000,uniform,0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters