Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 595b2be

Browse files
committed
Add counter class
The same as used in first project task - DataStructersCompatison Unfortunetly it breaks the project from working on Linux and as MinGW on Windows doesn't support random_device the only way to compile it is to use VisualStudio TTvTT
1 parent a2e1f88 commit 595b2be

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ if (CMAKE_BUILD_TYPE MATCHES RELEASE)
77
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
88
endif (CMAKE_BUILD_TYPE MATCHES RELEASE)
99

10-
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp MinHeapElement.cpp)
10+
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp MinHeapElement.cpp Counter.cpp)
1111
add_executable(GraphRepresentationsAndAlgorithmsComparison ${SOURCE_FILES})

Counter.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Created by barto on 18.04.17.
3+
//
4+
5+
#include "Counter.h"
6+
7+
// public
8+
9+
void Counter::startCounter() {
10+
LARGE_INTEGER li;
11+
if (!QueryPerformanceFrequency(&li))
12+
std::cout << "QueryPerformanceFrequency failed!\n";
13+
14+
PCFreq = double(li.QuadPart) / 1000000.0;
15+
16+
QueryPerformanceCounter(&li);
17+
CounterStart = li.QuadPart;
18+
}
19+
20+
double Counter::getCounter() {
21+
LARGE_INTEGER li;
22+
QueryPerformanceCounter(&li);
23+
return double(li.QuadPart - CounterStart) / PCFreq;
24+
}

Counter.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Created by barto on 18.04.17.
3+
//
4+
// Code written by Ramonster.
5+
// It was said in task description that we can use code from that link.
6+
//
7+
8+
#ifndef DATASTRUCTURESSDIZO_COUNTER_H
9+
#define DATASTRUCTURESSDIZO_COUNTER_H
10+
11+
12+
#include <windows.h>
13+
#include <iostream>
14+
15+
class Counter {
16+
private:
17+
18+
double PCFreq = 0.0;
19+
20+
__int64 CounterStart = 0;
21+
22+
public:
23+
24+
void startCounter();
25+
26+
double getCounter();
27+
28+
};
29+
30+
31+
#endif //DATASTRUCTURESSDIZO_COUNTER_H

0 commit comments

Comments
 (0)