Compare commits
No commits in common. "ff12edcdbe371f7364eedbf51025bfdbcfbc2923" and "2eade6e46b75b10dd66a3774e3b1f0a36327242e" have entirely different histories.
ff12edcdbe
...
2eade6e46b
9
.gitignore
vendored
9
.gitignore
vendored
@ -31,13 +31,4 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
quickhull
|
|
||||||
|
|
||||||
# VS project
|
|
||||||
*.vcxproj*
|
|
||||||
*.sln
|
|
||||||
Debug
|
|
||||||
Release
|
|
||||||
|
|
||||||
# additional win includes
|
|
||||||
SFML-2.5.1
|
|
||||||
|
20
Makefile
20
Makefile
@ -1,20 +0,0 @@
|
|||||||
CXX = g++
|
|
||||||
CXXFLAGS = -Wall -O3
|
|
||||||
|
|
||||||
# In case you installed SFML to a non-standard path, you'll need to tell the compiler where to find the SFML headers (.hpp files):
|
|
||||||
# g++ -c main.cpp -I<sfml-install-path>/include
|
|
||||||
|
|
||||||
# If SFML is not installed in a standard path, you need to tell the dynamic linker where to find the SFML libraries first by specifying LD_LIBRARY_PATH:
|
|
||||||
# export LD_LIBRARY_PATH=<sfml-install-path>/lib && ./sfml-app
|
|
||||||
|
|
||||||
quickhull: main.o Timing.o
|
|
||||||
# link with sfml libs; -lsfml-network -lsfml-audio currently not needed
|
|
||||||
$(CXX) $(CXXFLAGS) -o quickhull main.o Timing.o -lsfml-system -lsfml-window -lsfml-graphics
|
|
||||||
|
|
||||||
main.o: main.cpp Timing.h
|
|
||||||
$(CXX) $(CXXFLAGS) -c main.cpp
|
|
||||||
|
|
||||||
Timing.o: Timing.h
|
|
||||||
|
|
||||||
clean :
|
|
||||||
-rm *.o quickhull
|
|
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;
|
|
||||||
};
|
|
BIN
alg_prog2.pdf
BIN
alg_prog2.pdf
Binary file not shown.
29
main.cpp
29
main.cpp
@ -1,29 +0,0 @@
|
|||||||
// make sure sfml is installed:
|
|
||||||
// linux - sudo apt-get install libsfml-dev
|
|
||||||
// windows - manual dl from https://www.sfml-dev.org/download.php
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
|
|
||||||
#include "Timing.h"
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
|
|
||||||
sf::CircleShape shape(100.f);
|
|
||||||
shape.setFillColor(sf::Color::Green);
|
|
||||||
|
|
||||||
while (window.isOpen())
|
|
||||||
{
|
|
||||||
sf::Event event;
|
|
||||||
while (window.pollEvent(event))
|
|
||||||
{
|
|
||||||
if (event.type == sf::Event::Closed)
|
|
||||||
window.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.clear();
|
|
||||||
window.draw(shape);
|
|
||||||
window.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user