Debian Codegraph @

Source/Control/Loader/CTestHashModificationLoader.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CTestHashModificationLoader.h"
22
23
24 namespace Konclude {
25
26 namespace Control {
27
28 namespace Loader {
29
30
31 CTestHashModificationLoader::CTestHashModificationLoader() : CIntervalThread("TestHashModificationThread") {
32 mConfiguration = 0;
33 tester = 0;
34 startThread();
35 }
36
37
38
39 CTestHashModificationLoader::~CTestHashModificationLoader() {
40 }
41
42
43 CLoader* CTestHashModificationLoader::init(CLoaderFactory* loaderFactory, CConfiguration* config) {
44 mConfiguration = config;
45 return this;
46 }
47
48
49
50
51 CLoader *CTestHashModificationLoader::load() {
52 tester = new CConcurrentHashModificationTester();
53 mRemainingSteps = 1;
54 mThreadCount = 1;
55 mMaxThreadCount = 10;
56 mUseModificatedHashes = false;
57 mExtendBaseHashes = false;
58 mHashModCountPerStep = 4;
59 mMaxHashModCountPerStep = 16384;
60 tester->generateTestingStructure(mThreadCount,mHashModCountPerStep,mUseModificatedHashes,mExtendBaseHashes);
61 tester->startHashModificationTest();
62 startTimerWithInterval(TESTTIMERID,10000);
63 cout<<"Starting concurrent hash modification performance test.\n";
64 cout<<"----------------------\n";
65 return this;
66 }
67
68
69 bool CTestHashModificationLoader::processTimer(qint64 timerID) {
70 if (timerID == TESTTIMERID) {
71 if (mRemainingSteps > 0) {
72 cint64 modSteps = tester->getModificationStepsCount();
73 tester->stopHashModificationTest();
74 tester->destroyTestingStructure();
75 if (mThreadCount == 1) {
76 mOneThreadScore = modSteps;
77 }
78 cout<<""<<mThreadCount<<" \tThreads,";
79 if (mUseModificatedHashes) {
80 cout<<" using Modified-Qt-Hashes";
81 } else {
82 cout<<" using Original-Qt-Hashes";
83 }
84 cout<<", #Modifications per Step "<<mHashModCountPerStep;
85 if (mExtendBaseHashes) {
86 cout<<", \textending Hashes";
87 } else {
88 cout<<", \tbuild new Hashes";
89 }
90 cout<<" >> "<<"Hash Modification Score: \t"<<modSteps;
91 double scaleFac = (double)modSteps / (double)mOneThreadScore;
92 cout<<", \t"<<scaleFac<<"x"<<endl;
93
94
95 if (mThreadCount < mMaxThreadCount) {
96 ++mThreadCount;
97 } else {
98 mThreadCount = 1;
99 if (mHashModCountPerStep < mMaxHashModCountPerStep) {
100 mHashModCountPerStep *= 4;
101 } else {
102 mHashModCountPerStep = 4;
103 cout<<"----------------------\n";
104 if (!mExtendBaseHashes) {
105 mExtendBaseHashes = true;
106 } else {
107 mExtendBaseHashes = false;
108 if (!mUseModificatedHashes) {
109 mUseModificatedHashes = true;
110 } else {
111 // finish analyzing
112 mRemainingSteps = 0;
113 }
114 }
115 }
116 }
117
118 if (mRemainingSteps > 0) {
119 tester->generateTestingStructure(mThreadCount,mHashModCountPerStep,mUseModificatedHashes,mExtendBaseHashes);
120 tester->startHashModificationTest();
121 }
122
123 } else {
124 cout<<"Test finished.\n";
125 stopThread(false);
126 }
127 return true;
128 }
129 return false;
130 }
131
132
133 CLoader* CTestHashModificationLoader::exit() {
134 if (tester) {
135 delete tester;
136 }
137 return this;
138 }
139
140
141
142
143 }; // end namespace Loader
144
145 }; // end namespace Control
146
147 }; // end namespace Konclude