Compare commits
No commits in common. "2d5920532b39763e6a9c95cf40183411cb4ab46b" and "6654519d84c80e110ee18fe3361c15eda516cce5" have entirely different histories.
2d5920532b
...
6654519d84
8
Line.h
8
Line.h
@ -1,7 +1,4 @@
|
|||||||
#ifndef LINE_H
|
#pragma once
|
||||||
#define LINE_H
|
|
||||||
|
|
||||||
#include <cmath> // For abs, sqrt
|
|
||||||
|
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
|
||||||
@ -62,5 +59,4 @@ public:
|
|||||||
|
|
||||||
return (d * d) / (a * a + b * b);
|
return (d * d) / (a * a + b * b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // LINE_H
|
|
6
Point.h
6
Point.h
@ -1,5 +1,4 @@
|
|||||||
#ifndef POINT_H
|
#pragma once
|
||||||
#define POINT_H
|
|
||||||
|
|
||||||
class Point
|
class Point
|
||||||
{
|
{
|
||||||
@ -51,5 +50,4 @@ public:
|
|||||||
{
|
{
|
||||||
return (x() == other.x() && y() == other.y());
|
return (x() == other.x() && y() == other.y());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // POINT_H
|
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef QUICKHULL_H
|
#pragma once
|
||||||
#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,5 +149,4 @@ private:
|
|||||||
get_hull_with_line(left_of_line1, output, new_line1);
|
get_hull_with_line(left_of_line1, output, new_line1);
|
||||||
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
Normal file
168
Timing.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
#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
Normal file
33
Timing.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#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,5 +1,4 @@
|
|||||||
#ifndef TRIANGLE_H
|
#pragma once
|
||||||
#define TRIANGLE_H
|
|
||||||
|
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
#include "Line.h"
|
#include "Line.h"
|
||||||
@ -35,5 +34,4 @@ public:
|
|||||||
{
|
{
|
||||||
return m_l3;
|
return m_l3;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // TRIANGLE_H
|
|
@ -7,13 +7,8 @@ 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");
|
||||||
|
|
||||||
@ -55,5 +50,7 @@ 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