8 #include "LzmaBenchCon.h"
9 #include "../../../Common/IntToString.h"
11 #if defined(BENCH_MT) || defined(_WIN32)
12 #include "../../../Windows/System.h"
16 #include "../../UI/Console/ConsoleClose.h"
18 #include "../../../Common/MyCom.h"
26 void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }
29 if (NumIterations == 0)
31 Rating /= NumIterations;
32 Usage /= NumIterations;
36 void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
38 Rating = (r1.Rating + r2.Rating) / 2;
39 Usage = (r1.Usage + r2.Usage) / 2;
40 RPU = (r1.RPU + r2.RPU) / 2;
41 NumIterations = (r1.NumIterations + r2.NumIterations) / 2;
45 struct CBenchCallback: public IBenchCallback
47 CTotalBenchRes EncodeRes;
48 CTotalBenchRes DecodeRes;
50 void Init() { EncodeRes.Init(); DecodeRes.Init(); }
51 void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }
52 UInt32 dictionarySize;
53 HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
54 HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
57 static void NormalizeVals(UInt64 &v1, UInt64 &v2)
66 static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
68 UInt64 elTime = elapsedTime;
69 NormalizeVals(freq, elTime);
72 return value * freq / elTime;
75 static void PrintNumber(FILE *f, UInt64 value, int size)
78 ConvertUInt64ToString(value, s);
80 for (int len = (int)strlen(s); len < size; len++)
85 static void PrintRating(FILE *f, UInt64 rating)
87 PrintNumber(f, rating / 1000000, 6);
90 static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
92 PrintNumber(f, (usage + 5000) / 10000, 5);
94 PrintRating(f, rating);
98 static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)
100 UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);
101 PrintNumber(f, speed / 1024, 7);
102 UInt64 usage = GetUsage(info);
103 UInt64 rpu = GetRatingPerUsage(info, rating);
104 PrintResults(f, usage, rpu, rating);
107 res.Rating += rating;
111 static void PrintTotals(FILE *f, const CTotalBenchRes &res)
114 PrintResults(f, res.Usage, res.RPU, res.Rating);
118 HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
121 if (NConsoleClose::TestBreakSignal())
127 UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);
128 PrintResults(f, info, rating, EncodeRes);
133 static const char *kSep = " | ";
136 HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
139 if (NConsoleClose::TestBreakSignal())
144 UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
146 CBenchInfo info2 = info;
147 info2.UnpackSize *= info2.NumIterations;
148 info2.PackSize *= info2.NumIterations;
149 info2.NumIterations = 1;
150 PrintResults(f, info2, rating, DecodeRes);
155 static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
157 fprintf(f, "\nRAM %s ", sizeString);
158 PrintNumber(f, (size >> 20), 5);
159 fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads);
162 HRESULT LzmaBenchCon(
166 FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
168 if (!CrcInternalTest())
171 UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
172 UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
173 PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
174 if (numThreads == (UInt32)-1)
175 numThreads = numCPUs;
178 if (dictionary == (UInt32)-1)
181 for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
182 if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)
184 dictionary = (1 << dicSizeLog);
187 if (dictionary == (UInt32)-1)
188 dictionary = (1 << 22);
192 PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
194 CBenchCallback callback;
198 fprintf(f, "\n\nDict Compressing | Decompressing\n ");
200 for (j = 0; j < 2; j++)
202 fprintf(f, " Speed Usage R/U Rating");
207 for (j = 0; j < 2; j++)
209 fprintf(f, " KB/s %% MIPS MIPS");
214 for (UInt32 i = 0; i < numIterations; i++)
216 const int kStartDicLog = 22;
217 int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;
218 while (((UInt32)1 << pow) > dictionary)
220 for (; ((UInt32)1 << pow) <= dictionary; pow++)
222 fprintf(f, "%2d:", pow);
223 callback.dictionarySize = (UInt32)1 << pow;
224 HRESULT res = LzmaBench(
228 numThreads, callback.dictionarySize, &callback);
233 callback.Normalize();
234 fprintf(f, "----------------------------------------------------------------\nAvr:");
235 PrintTotals(f, callback.EncodeRes);
237 PrintTotals(f, callback.DecodeRes);
238 fprintf(f, "\nTot:");
239 CTotalBenchRes midRes;
240 midRes.SetMid(callback.EncodeRes, callback.DecodeRes);
241 PrintTotals(f, midRes);
249 CTempValues(UInt32 num) { Values = new UInt64[num]; }
250 ~CTempValues() { delete []Values; }
253 HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
255 if (!CrcInternalTest())
259 UInt64 ramSize = NWindows::NSystem::GetRamSize();
260 UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
261 PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
262 if (numThreads == (UInt32)-1)
263 numThreads = numCPUs;
267 if (dictionary == (UInt32)-1)
268 dictionary = (1 << 24);
270 CTempValues speedTotals(numThreads);
271 fprintf(f, "\n\nSize");
272 for (UInt32 ti = 0; ti < numThreads; ti++)
274 fprintf(f, " %5d", ti + 1);
275 speedTotals.Values[ti] = 0;
280 for (UInt32 i = 0; i < numIterations; i++)
282 for (int pow = 10; pow < 32; pow++)
284 UInt32 bufSize = (UInt32)1 << pow;
285 if (bufSize > dictionary)
287 fprintf(f, "%2d: ", pow);
289 for (UInt32 ti = 0; ti < numThreads; ti++)
292 if (NConsoleClose::TestBreakSignal())
295 RINOK(CrcBench(ti + 1, bufSize, speed));
296 PrintNumber(f, (speed >> 20), 5);
297 speedTotals.Values[ti] += speed;
305 fprintf(f, "\nAvg:");
306 for (UInt32 ti = 0; ti < numThreads; ti++)
307 PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);