-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.cpp
115 lines (97 loc) · 3 KB
/
benchmark.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "benchmark.h"
#include <limits>
#include <iostream>
#include <QFile>
#include <QString>
#include <QTextStream>
Benchmark::Benchmark()
{}
Benchmark::~Benchmark()
{
}
void Benchmark::worstCaseExtractMinTest(int nodes)
{
FibHeapBenchmark *heap = new FibHeapBenchmark(nodes); // 10000000 = OK, 50000000 = too high
heap->GenerateWorsCase();
// QElapsedTimer time;
// time.start();
// heap->ExtractMin();
// std::cout << nodes << ": " << time.elapsed() << " ms" << std::endl;
// std::cout << nodes << ": " << time.nsecsElapsed() << " ns" << std::endl;
delete heap;
}
void Benchmark::test()
{
QElapsedTimer time;
FibHeapBenchmark *heap = new FibHeapBenchmark(10000000); // 10000000 = OK, 50000000 = too high
heap->GenerateWorsCase(); // 10000000
time.start();
heap->ExtractMin();
std::cout << 10000000 << ": " << time.elapsed() << " ms" << std::endl;
heap->ResetWorsCase(); //9999999
time.restart();
time.start();
heap->ExtractMin();
std::cout << 9999999 << ": " << time.elapsed() << " ms" << std::endl;
heap->ResetWorsCase(); //9999998
time.restart();
time.start();
heap->ExtractMin();
std::cout << 9999998 << ": " << time.elapsed() << " ms" << std::endl;
heap->ResetWorsCase(); //9999997
time.restart();
time.start();
heap->ExtractMin();
std::cout << 9999997 << ": " << time.elapsed() << " ms" << std::endl;
delete heap;
}
void Benchmark::worstCaseExtractMin(int nodes)
{
FibHeapBenchmark *heap = new FibHeapBenchmark(nodes); // 10000000 = OK, 50000000 = too high
int i = 0;
qint64 timeElapsed;
while(heap->WorsCaseOneUp())
{
QElapsedTimer time;
time.start();
heap->ExtractMin();
timeElapsed = time.nsecsElapsed();
std::cout << ++i << ":\t"
<< timeElapsed
<< " ns\t"
<< (int)(timeElapsed/1000000)
<< " ms\t"
<< std::endl;
}
delete heap;
}
void Benchmark::worstCaseExtractMinOutFiles(int nodes, int outFiles)
{
FibHeapBenchmark *heap = new FibHeapBenchmark(nodes); // 10000000 = OK, 50000000 = too high
heap->initNodes(); // we do this only once
for(int fileIndex = 0; fileIndex < outFiles; ++fileIndex)
{
QString FileName = "wcExMinResaults" + QString::number(fileIndex);
QFile datoteka(FileName);
datoteka.open(QIODevice::WriteOnly);
QTextStream out(&datoteka);
heap->upCountReset(); // set the upCount to 0
int i = 0;
qint64 timeElapsed;
while(heap->WorsCaseUp())
{
QElapsedTimer time;
time.start();
heap->ExtractMin();
timeElapsed = time.nsecsElapsed();
out << i++ << ":\t"
<< timeElapsed
<< " ns\t"
<< (int)(timeElapsed/1000000)
<< " ms\t"
<< "\n";
}
datoteka.close();
}
delete heap;
}