Compare commits
3 Commits
6654519d84
...
2d5920532b
Author | SHA1 | Date | |
---|---|---|---|
2d5920532b | |||
6056640ad4 | |||
dce7bb581b |
6
Line.h
6
Line.h
@ -1,4 +1,7 @@
|
|||||||
#pragma once
|
#ifndef LINE_H
|
||||||
|
#define LINE_H
|
||||||
|
|
||||||
|
#include <cmath> // For abs, sqrt
|
||||||
|
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
|
||||||
@ -60,3 +63,4 @@ public:
|
|||||||
return (d * d) / (a * a + b * b);
|
return (d * d) / (a * a + b * b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif // LINE_H
|
4
Point.h
4
Point.h
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef POINT_H
|
||||||
|
#define POINT_H
|
||||||
|
|
||||||
class Point
|
class Point
|
||||||
{
|
{
|
||||||
@ -51,3 +52,4 @@ public:
|
|||||||
return (x() == other.x() && y() == other.y());
|
return (x() == other.x() && y() == other.y());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif // POINT_H
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef QUICKHULL_H
|
||||||
|
#define QUICKHULL_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <bits/stdc++.h> // For INT_MIN & INT_MAX
|
#include <bits/stdc++.h> // For INT_MIN & INT_MAX
|
||||||
@ -150,3 +151,4 @@ private:
|
|||||||
get_hull_with_line(left_of_line2, output, new_line2);
|
get_hull_with_line(left_of_line2, output, new_line2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif // QUICKHULL_H
|
168
Timing.cpp
168
Timing.cpp
@ -1,168 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip> // setw for padleft
|
|
||||||
|
|
||||||
#include "Timing.h"
|
|
||||||
|
|
||||||
Timing* Timing::mInstance = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Singleton: Get instance.
|
|
||||||
*/
|
|
||||||
Timing* Timing::getInstance() {
|
|
||||||
if (mInstance == 0) {
|
|
||||||
mInstance = new Timing();
|
|
||||||
}
|
|
||||||
|
|
||||||
return mInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start recording time with any name.
|
|
||||||
*/
|
|
||||||
void Timing::startRecord(const std::string& name) {
|
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
auto it = mRecordings.find(name);
|
|
||||||
if (it != mRecordings.end()) {
|
|
||||||
it->second = start;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mRecordings.insert(std::pair<std::string, std::chrono::high_resolution_clock::time_point>(name, start));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop recording time with any name.
|
|
||||||
*/
|
|
||||||
void Timing::stopRecord(const std::string& name) {
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
auto it = mRecordings.find(name);
|
|
||||||
if (it != mRecordings.end()) {
|
|
||||||
auto start = it->second;
|
|
||||||
auto result = end - start;
|
|
||||||
|
|
||||||
mResults.insert(std::pair<std::string, std::chrono::duration<double, std::milli> >(name, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Print measured results human-readable.
|
|
||||||
* Set prettyPrint to true to display mm:ss.ms instead of ms.
|
|
||||||
*/
|
|
||||||
void Timing::print(const bool prettyPrint) const {
|
|
||||||
std::cout << "--------------------" << std::endl << "Results: " << std::endl << "--------------------" << std::endl;
|
|
||||||
auto it = mResults.begin();
|
|
||||||
while (it != mResults.end()) {
|
|
||||||
if (prettyPrint) {
|
|
||||||
std::cout << it->first << ": " << parseDate((int)it->second.count()) << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << it->first << ": " << std::setfill(' ') << std::setw(10) << std::fixed << std::setprecision(4) << it->second.count() << "ms" << std::endl;
|
|
||||||
}
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
std::cout << "--------------------" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse date from ms to mm:ss.ms.
|
|
||||||
*/
|
|
||||||
std::string Timing::parseDate(const int ms) const {
|
|
||||||
int minutes = (int)(ms / 1000 / 60);
|
|
||||||
int seconds = (int)((ms % (1000 * 60)) / 1000);
|
|
||||||
int milliseconds = (int)(ms % 1000);
|
|
||||||
|
|
||||||
std::ostringstream stringStream;
|
|
||||||
if (seconds == 60) {
|
|
||||||
stringStream << minutes + 1 << ":00" << seconds << ".";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stringStream << minutes << ":" << (seconds < 10 ? "0" : "") << seconds << ".";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (milliseconds < 100) {
|
|
||||||
if (milliseconds < 10) {
|
|
||||||
stringStream << "00" << milliseconds;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stringStream << "0" << milliseconds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stringStream << milliseconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringStream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get results of setup, computation and finalization in form:
|
|
||||||
* mm:ss.ms;mm:ss.ms;mm.ss.ms
|
|
||||||
*/
|
|
||||||
std::string Timing::getResults() const {
|
|
||||||
std::ostringstream stringStream;
|
|
||||||
|
|
||||||
auto start = mResults.find("setup");
|
|
||||||
if (start != mResults.end()) {
|
|
||||||
stringStream << parseDate((int)start->second.count()) << ";";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto computation = mResults.find("computation");
|
|
||||||
if (computation != mResults.end()) {
|
|
||||||
stringStream << parseDate((int)computation->second.count()) << ";";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto finalization = mResults.find("finalization");
|
|
||||||
if (start != mResults.end()) {
|
|
||||||
stringStream << parseDate((int)finalization->second.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringStream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start recording the setup time.
|
|
||||||
*/
|
|
||||||
void Timing::startSetup() {
|
|
||||||
this->startRecord("setup");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop recording the setup time.
|
|
||||||
*/
|
|
||||||
void Timing::stopSetup() {
|
|
||||||
this->stopRecord("setup");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start recording the computation time.
|
|
||||||
*/
|
|
||||||
void Timing::startComputation() {
|
|
||||||
this->startRecord("computation");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop recording the computation time.
|
|
||||||
*/
|
|
||||||
void Timing::stopComputation() {
|
|
||||||
this->stopRecord("computation");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start recording the finalization time.
|
|
||||||
*/
|
|
||||||
void Timing::startFinalization() {
|
|
||||||
this->startRecord("finalization");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop recording the finalization time.
|
|
||||||
*/
|
|
||||||
void Timing::stopFinalization() {
|
|
||||||
this->stopRecord("finalization");
|
|
||||||
}
|
|
33
Timing.h
33
Timing.h
@ -1,33 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <chrono>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Measure high precision time intervals (using std::chrono).
|
|
||||||
* Author: Karl Hofer <hoferk@technikum-wien.at>
|
|
||||||
*/
|
|
||||||
class Timing {
|
|
||||||
public:
|
|
||||||
static Timing* getInstance();
|
|
||||||
|
|
||||||
void startSetup();
|
|
||||||
void stopSetup();
|
|
||||||
void startComputation();
|
|
||||||
void stopComputation();
|
|
||||||
void startFinalization();
|
|
||||||
void stopFinalization();
|
|
||||||
|
|
||||||
void startRecord(const std::string& name);
|
|
||||||
void stopRecord(const std::string& name);
|
|
||||||
void print(const bool prettyPrint = false) const;
|
|
||||||
std::string getResults() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Timing() {};
|
|
||||||
std::map<std::string, std::chrono::high_resolution_clock::time_point > mRecordings;
|
|
||||||
std::map<std::string, std::chrono::duration<double, std::milli> > mResults;
|
|
||||||
std::string parseDate(const int ms) const;
|
|
||||||
|
|
||||||
static Timing* mInstance;
|
|
||||||
};
|
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef TRIANGLE_H
|
||||||
|
#define TRIANGLE_H
|
||||||
|
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
#include "Line.h"
|
#include "Line.h"
|
||||||
@ -35,3 +36,4 @@ public:
|
|||||||
return m_l3;
|
return m_l3;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif // TRIANGLE_H
|
@ -7,8 +7,13 @@ int main()
|
|||||||
std::list<Point> points = NumberGenerator::get_rectangle_numbers(100);
|
std::list<Point> points = NumberGenerator::get_rectangle_numbers(100);
|
||||||
std::list<Point> hull;
|
std::list<Point> hull;
|
||||||
|
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
Quickhull::get_hull(points, hull);
|
Quickhull::get_hull(points, hull);
|
||||||
|
|
||||||
|
auto diff = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - start);
|
||||||
|
std::cout << "time spent: " << diff.count() << "ms" << std::endl; // shit runs about 120 milliseconds for 1Mio numbers
|
||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
sf::RenderWindow window(sf::VideoMode(800, 800), "k-d-tree");
|
sf::RenderWindow window(sf::VideoMode(800, 800), "k-d-tree");
|
||||||
|
|
||||||
@ -50,7 +55,5 @@ int main()
|
|||||||
// end the current frame
|
// end the current frame
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user