xref: /third_party/lzma/CPP/7zip/UI/Common/Bench.h (revision 370b324c)
1// Bench.h
2
3#ifndef ZIP7_INC_7ZIP_BENCH_H
4#define ZIP7_INC_7ZIP_BENCH_H
5
6#include "../../../Windows/System.h"
7
8#include "../../Common/CreateCoder.h"
9#include "../../UI/Common/Property.h"
10
11UInt64 Benchmark_GetUsage_Percents(UInt64 usage);
12
13struct CBenchInfo
14{
15  UInt64 GlobalTime;
16  UInt64 GlobalFreq;
17  UInt64 UserTime;
18  UInt64 UserFreq;
19  UInt64 UnpackSize;
20  UInt64 PackSize;
21  UInt64 NumIterations;
22
23  /*
24     during Code(): we track benchInfo only from one thread (theads with index[0])
25       NumIterations means number of threads
26       UnpackSize and PackSize are total sizes of all iterations of current thread
27     after Code():
28       NumIterations means the number of Iterations
29       UnpackSize and PackSize are total sizes of all threads
30  */
31
32  CBenchInfo(): NumIterations(0) {}
33
34  UInt64 GetUsage() const;
35  UInt64 GetRatingPerUsage(UInt64 rating) const;
36  UInt64 GetSpeed(UInt64 numUnits) const;
37  UInt64 GetUnpackSizeSpeed() const { return GetSpeed(UnpackSize * NumIterations); }
38
39  UInt64 Get_UnpackSize_Full() const { return UnpackSize * NumIterations; }
40
41  UInt64 GetRating_LzmaEnc(UInt64 dictSize) const;
42  UInt64 GetRating_LzmaDec() const;
43};
44
45
46struct CTotalBenchRes
47{
48  // UInt64 NumIterations1; // for Usage
49  UInt64 NumIterations2; // for Rating / RPU
50
51  UInt64 Rating;
52  UInt64 Usage;
53  UInt64 RPU;
54  UInt64 Speed;
55
56  void Init() { /* NumIterations1 = 0; */ NumIterations2 = 0; Rating = 0; Usage = 0; RPU = 0; Speed = 0; }
57
58  void SetSum(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
59  {
60    Rating = (r1.Rating + r2.Rating);
61    Usage = (r1.Usage + r2.Usage);
62    RPU = (r1.RPU + r2.RPU);
63    Speed = (r1.Speed + r2.Speed);
64    // NumIterations1 = (r1.NumIterations1 + r2.NumIterations1);
65    NumIterations2 = (r1.NumIterations2 + r2.NumIterations2);
66  }
67
68  void Generate_From_BenchInfo(const CBenchInfo &info);
69  void Mult_For_Weight(unsigned weight);
70  void Update_With_Res(const CTotalBenchRes &r);
71};
72
73
74const unsigned kBenchMinDicLogSize = 18;
75
76UInt64 GetBenchMemoryUsage(UInt32 numThreads, int level, UInt64 dictionary, bool totalBench);
77
78Z7_PURE_INTERFACES_BEGIN
79DECLARE_INTERFACE(IBenchCallback)
80{
81  // virtual HRESULT SetFreq(bool showFreq, UInt64 cpuFreq) = 0;
82  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
83  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
84};
85
86DECLARE_INTERFACE(IBenchPrintCallback)
87{
88  virtual void Print(const char *s) = 0;
89  virtual void NewLine() = 0;
90  virtual HRESULT CheckBreak() = 0;
91};
92
93DECLARE_INTERFACE(IBenchFreqCallback)
94{
95  virtual HRESULT AddCpuFreq(unsigned numThreads, UInt64 freq, UInt64 usage) = 0;
96  virtual HRESULT FreqsFinished(unsigned numThreads) = 0;
97};
98Z7_PURE_INTERFACES_END
99
100HRESULT Bench(
101    DECL_EXTERNAL_CODECS_LOC_VARS
102    IBenchPrintCallback *printCallback,
103    IBenchCallback *benchCallback,
104    const CObjectVector<CProperty> &props,
105    UInt32 numIterations,
106    bool multiDict,
107    IBenchFreqCallback *freqCallback = NULL);
108
109AString GetProcessThreadsInfo(const NWindows::NSystem::CProcessAffinity &ti);
110
111void GetSysInfo(AString &s1, AString &s2);
112void GetCpuName(AString &s);
113void AddCpuFeatures(AString &s);
114
115#ifdef Z7_LARGE_PAGES
116void Add_LargePages_String(AString &s);
117#else
118// #define Add_LargePages_String
119#endif
120
121#endif
122