diff options
author | 2023-12-06 07:58:49 +1100 | |
---|---|---|
committer | 2023-12-06 07:58:49 +1100 | |
commit | 79bef1e23049fdac25f1fefd132e0b6c7d2cc3a1 (patch) | |
tree | 643e9313fe86f583c4022c338677cbc12b761df7 /3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp | |
parent | 512ccf0c7c9b4f08e41038b2ed2de220e140385b (diff) |
3rdparty/lzma: Updated to version 23.01.
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp | 1105 |
1 files changed, 697 insertions, 408 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp index cc0cfd0c433..5da9783d4e1 100644 --- a/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp +++ b/3rdparty/lzma/CPP/7zip/UI/Common/Bench.cpp @@ -36,19 +36,20 @@ #include "../../../../C/7zCrc.h" #include "../../../../C/RotateDefs.h" -#ifndef _7ZIP_ST +#ifndef Z7_ST #include "../../../Windows/Synchronization.h" #include "../../../Windows/Thread.h" #endif -#include "../../../Windows/FileIO.h" #include "../../../Windows/FileFind.h" +#include "../../../Windows/FileIO.h" #include "../../../Windows/SystemInfo.h" -#include "../../../Common/IntToString.h" #include "../../../Common/MyBuffer2.h" +#include "../../../Common/IntToString.h" #include "../../../Common/StringConvert.h" #include "../../../Common/StringToInt.h" +#include "../../../Common/Wildcard.h" #include "../../Common/MethodProps.h" #include "../../Common/StreamObjects.h" @@ -58,7 +59,7 @@ using namespace NWindows; -#ifndef _7ZIP_ST +#ifndef Z7_ST static const UInt32 k_LZMA = 0x030101; #endif @@ -122,7 +123,7 @@ class CBaseRandomGenerator public: CBaseRandomGenerator(UInt32 salt = 0): Salt(salt) { Init(); } void Init() { A1 = 362436069; A2 = 521288629;} - MY_FORCE_INLINE + Z7_FORCE_INLINE UInt32 GetRnd() { return Salt ^ @@ -134,7 +135,7 @@ public: }; -MY_NO_INLINE +Z7_NO_INLINE static void RandGen(Byte *buf, size_t size) { CBaseRandomGenerator RG; @@ -143,7 +144,7 @@ static void RandGen(Byte *buf, size_t size) for (i = 0; i < size4; i += 4) { const UInt32 v = RG.GetRnd(); - SetUi32(buf + i, v); + SetUi32(buf + i, v) } UInt32 v = RG.GetRnd(); for (; i < size; i++) @@ -255,16 +256,14 @@ public: }; -class CBenchmarkInStream: - public ISequentialInStream, - public CMyUnknownImp -{ +Z7_CLASS_IMP_NOQIB_1( + CBenchmarkInStream + , ISequentialInStream +) const Byte *Data; size_t Pos; size_t Size; - public: - MY_UNKNOWN_IMP void Init(const Byte *data, size_t size) { Data = data; @@ -272,10 +271,9 @@ public: Pos = 0; } bool WasFinished() const { return Pos == Size; } - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); }; -STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize) +Z7_COM7F_IMF(CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)) { const UInt32 kMaxBlockSize = (1 << 20); if (size > kMaxBlockSize) @@ -293,11 +291,14 @@ STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processed return S_OK; } -class CBenchmarkOutStream: + +class CBenchmarkOutStream Z7_final: public ISequentialOutStream, - public CMidAlignedBuffer, - public CMyUnknownImp + public CMyUnknownImp, + public CMidAlignedBuffer { + Z7_COM_UNKNOWN_IMP_0 + Z7_IFACE_COM7_IMP(ISequentialOutStream) // bool _overflow; public: size_t Pos; @@ -328,12 +329,9 @@ public: size_t GetPos() const { return Pos; } // void Print() { printf("\n%8d %8d\n", (unsigned)BufferSize, (unsigned)Pos); } - - MY_UNKNOWN_IMP - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); }; -STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) +Z7_COM7F_IMF(CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)) { size_t curSize = Size() - Pos; if (curSize > size) @@ -357,27 +355,24 @@ STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *p } -class CCrcOutStream: - public ISequentialOutStream, - public CMyUnknownImp -{ +Z7_CLASS_IMP_NOQIB_1( + CCrcOutStream + , ISequentialOutStream +) public: bool CalcCrc; UInt32 Crc; UInt64 Pos; - MY_UNKNOWN_IMP - - CCrcOutStream(): CalcCrc(true) {}; + CCrcOutStream(): CalcCrc(true) {} void Init() { Crc = CRC_INIT_VAL; Pos = 0; } void Calc(const void *data, size_t size) { Crc = CrcUpdate(Crc, data, size); } - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); }; -STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) +Z7_COM7F_IMF(CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)) { if (CalcCrc) Calc(data, size); @@ -394,7 +389,7 @@ static UInt64 GetTimeCount() #ifdef USE_POSIX_TIME #ifdef USE_POSIX_TIME2 timeval v; - if (gettimeofday(&v, 0) == 0) + if (gettimeofday(&v, NULL) == 0) return (UInt64)(v.tv_sec) * 1000000 + (UInt64)v.tv_usec; return (UInt64)time(NULL) * 1000000; #else @@ -531,9 +526,9 @@ static UInt64 GetUserFreq() #endif } -class CBenchProgressStatus +class CBenchProgressStatus Z7_final { - #ifndef _7ZIP_ST + #ifndef Z7_ST NSynchronization::CCriticalSection CS; #endif public: @@ -541,14 +536,14 @@ public: bool EncodeMode; void SetResult(HRESULT res) { - #ifndef _7ZIP_ST + #ifndef Z7_ST NSynchronization::CCriticalSectionLock lock(CS); #endif Res = res; } HRESULT GetResult() { - #ifndef _7ZIP_ST + #ifndef Z7_ST NSynchronization::CCriticalSectionLock lock(CS); #endif return Res; @@ -580,22 +575,22 @@ void CBenchInfoCalc::SetFinishTime(CBenchInfo &dest) dest.UserTime = UserTime.GetUserTime(); } -class CBenchProgressInfo: +class CBenchProgressInfo Z7_final: public ICompressProgressInfo, public CMyUnknownImp, public CBenchInfoCalc { + Z7_COM_UNKNOWN_IMP_0 + Z7_IFACE_COM7_IMP(ICompressProgressInfo) public: CBenchProgressStatus *Status; IBenchCallback *Callback; CBenchProgressInfo(): Callback(NULL) {} - MY_UNKNOWN_IMP - STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); }; -STDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) +Z7_COM7F_IMF(CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)) { HRESULT res = Status->GetResult(); if (res != S_OK) @@ -760,13 +755,20 @@ UInt64 CBenchInfo::GetSpeed(UInt64 numUnits) const return MyMultDiv64(numUnits, GlobalFreq, GlobalTime); } +static UInt64 GetNumCommands_from_Size_and_Complexity(UInt64 size, Int32 complexity) +{ + return complexity >= 0 ? + size * (UInt32)complexity : + size / (UInt32)(-complexity); +} + struct CBenchProps { bool LzmaRatingMode; - UInt32 EncComplex; - UInt32 DecComplexCompr; - UInt32 DecComplexUnc; + Int32 EncComplex; + Int32 DecComplexCompr; + Int32 DecComplexUnc; unsigned KeySize; @@ -777,21 +779,23 @@ struct CBenchProps void SetLzmaCompexity(); - UInt64 GeComprCommands(UInt64 unpackSize) + UInt64 GetNumCommands_Enc(UInt64 unpackSize) const { const UInt32 kMinSize = 100; if (unpackSize < kMinSize) unpackSize = kMinSize; - return unpackSize * EncComplex; + return GetNumCommands_from_Size_and_Complexity(unpackSize, EncComplex); } - UInt64 GeDecomprCommands(UInt64 packSize, UInt64 unpackSize) + UInt64 GetNumCommands_Dec(UInt64 packSize, UInt64 unpackSize) const { - return (packSize * DecComplexCompr + unpackSize * DecComplexUnc); + return + GetNumCommands_from_Size_and_Complexity(packSize, DecComplexCompr) + + GetNumCommands_from_Size_and_Complexity(unpackSize, DecComplexUnc); } - UInt64 GetCompressRating(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size); - UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations); + UInt64 GetRating_Enc(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size) const; + UInt64 GetRating_Dec(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations) const; }; void CBenchProps::SetLzmaCompexity() @@ -802,11 +806,11 @@ void CBenchProps::SetLzmaCompexity() LzmaRatingMode = true; } -UInt64 CBenchProps::GetCompressRating(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size) +UInt64 CBenchProps::GetRating_Enc(UInt64 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size) const { if (dictSize < (1 << kBenchMinDicLogSize)) dictSize = (1 << kBenchMinDicLogSize); - UInt64 encComplex = EncComplex; + Int32 encComplex = EncComplex; if (LzmaRatingMode) { /* @@ -822,13 +826,13 @@ UInt64 CBenchProps::GetCompressRating(UInt64 dictSize, UInt64 elapsedTime, UInt6 const UInt32 t = GetLogSize_Sub(dictSize) - (kBenchMinDicLogSize << kSubBits); encComplex = 870 + ((t * t * 5) >> (2 * kSubBits)); } - const UInt64 numCommands = (UInt64)size * encComplex; + const UInt64 numCommands = GetNumCommands_from_Size_and_Complexity(size, encComplex); return MyMultDiv64(numCommands, freq, elapsedTime); } -UInt64 CBenchProps::GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations) +UInt64 CBenchProps::GetRating_Dec(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt64 numIterations) const { - const UInt64 numCommands = (inSize * DecComplexCompr + outSize * DecComplexUnc) * numIterations; + const UInt64 numCommands = GetNumCommands_Dec(inSize, outSize) * numIterations; return MyMultDiv64(numCommands, freq, elapsedTime); } @@ -838,18 +842,18 @@ UInt64 CBenchInfo::GetRating_LzmaEnc(UInt64 dictSize) const { CBenchProps props; props.SetLzmaCompexity(); - return props.GetCompressRating(dictSize, GlobalTime, GlobalFreq, UnpackSize * NumIterations); + return props.GetRating_Enc(dictSize, GlobalTime, GlobalFreq, UnpackSize * NumIterations); } UInt64 CBenchInfo::GetRating_LzmaDec() const { CBenchProps props; props.SetLzmaCompexity(); - return props.GetDecompressRating(GlobalTime, GlobalFreq, UnpackSize, PackSize, NumIterations); + return props.GetRating_Dec(GlobalTime, GlobalFreq, UnpackSize, PackSize, NumIterations); } -#ifndef _7ZIP_ST +#ifndef Z7_ST #define NUM_CPU_LEVELS_MAX 3 @@ -988,15 +992,22 @@ struct CBenchSyncCommon +enum E_CheckCrcMode +{ + k_CheckCrcMode_Never = 0, + k_CheckCrcMode_Always = 1, + k_CheckCrcMode_FirstPass = 2 +}; + class CEncoderInfo; -class CEncoderInfo +class CEncoderInfo Z7_final { - CLASS_NO_COPY(CEncoderInfo) + Z7_CLASS_NO_COPY(CEncoderInfo) public: - #ifndef _7ZIP_ST + #ifndef Z7_ST NWindows::CThread thread[2]; NSynchronization::CManualResetEvent ReadyEvent; UInt32 NumDecoderSubThreads; @@ -1004,6 +1015,7 @@ public: UInt32 EncoderIndex; UInt32 NumEncoderInternalThreads; CAffinityMode AffinityMode; + bool IsGlobalMtMode; // if more than one benchmark encoder threads #endif CMyComPtr<ICompressCoder> _encoder; @@ -1024,14 +1036,17 @@ public: HRESULT Set_Key_and_IV(ICryptoProperties *cp) { - RINOK(cp->SetKey(_key, KeySize)); + RINOK(cp->SetKey(_key, KeySize)) return cp->SetInitVector(_iv, sizeof(_iv)); } Byte _psw[16]; - bool CheckCrc_Enc; - bool CheckCrc_Dec; + bool CheckCrc_Enc; /* = 1, if we want to check packed data crcs after each pass + used for filter and usual coders */ + bool UseRealData_Enc; /* = 1, if we want to use only original data for each pass + used only for filter */ + E_CheckCrcMode CheckCrcMode_Dec; struct CDecoderInfo { @@ -1079,13 +1094,15 @@ public: HRESULT Decode(UInt32 decoderIndex); CEncoderInfo(): - #ifndef _7ZIP_ST + #ifndef Z7_ST Common(NULL), + IsGlobalMtMode(true), #endif Salt(0), KeySize(0), CheckCrc_Enc(true), - CheckCrc_Dec(true), + UseRealData_Enc(true), + CheckCrcMode_Dec(k_CheckCrcMode_Always), outStreamSpec(NULL), callback(NULL), printCallback(NULL), @@ -1093,7 +1110,7 @@ public: propStreamSpec(NULL) {} - #ifndef _7ZIP_ST + #ifndef Z7_ST static THREAD_FUNC_DECL EncodeThreadFunction(void *param) { @@ -1115,7 +1132,7 @@ public: if (res != S_OK) encoder->progressInfoSpec[0]->Status->SetResult(res); encoder->ReadyEvent.Set(); - return 0; + return THREAD_FUNC_RET_ZERO; } static THREAD_FUNC_DECL DecodeThreadFunction(void *param) @@ -1128,7 +1145,7 @@ public: CEncoderInfo *encoder = decoder->Encoder; encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex); - return 0; + return THREAD_FUNC_RET_ZERO; } HRESULT CreateEncoderThread() @@ -1184,17 +1201,30 @@ HRESULT CEncoderInfo::Generate() const COneMethodInfo &method = _method; // we need extra space, if input data is already compressed - const size_t kCompressedBufferSize = GetBenchCompressedSize(kBufferSize); + const size_t kCompressedBufferSize = _encoderFilter ? + kBufferSize : + GetBenchCompressedSize(kBufferSize); if (kCompressedBufferSize < kBufferSize) return E_FAIL; uncompressedDataPtr = fileData; - - if (!fileData) + if (fileData) { - ALLOC_WITH_HRESULT(&rg, kBufferSize); - + #if !defined(Z7_ST) + if (IsGlobalMtMode) + { + /* we copy the data to local buffer of thread to eliminate + using of shared buffer by different threads */ + ALLOC_WITH_HRESULT(&rg, kBufferSize) + memcpy((Byte *)rg, fileData, kBufferSize); + uncompressedDataPtr = (const Byte *)rg; + } + #endif + } + else + { + ALLOC_WITH_HRESULT(&rg, kBufferSize) // DWORD ttt = GetTickCount(); if (generateDictBits == 0) rg.GenerateSimpleRandom(Salt); @@ -1211,12 +1241,6 @@ HRESULT CEncoderInfo::Generate() crc = CrcCalc((const Byte *)rg, rg.Size()); uncompressedDataPtr = (const Byte *)rg; } - - if (_encoderFilter) - { - ALLOC_WITH_HRESULT(&rgCopy, kBufferSize); - } - if (!outStream) { @@ -1226,6 +1250,15 @@ HRESULT CEncoderInfo::Generate() ALLOC_WITH_HRESULT(outStreamSpec, kCompressedBufferSize) + if (_encoderFilter) + { + /* we try to reduce the number of memcpy() in main encoding loop. + so we copy data to temp buffers here */ + ALLOC_WITH_HRESULT(&rgCopy, kBufferSize) + memcpy((Byte *)*outStreamSpec, uncompressedDataPtr, kBufferSize); + memcpy((Byte *)rgCopy, uncompressedDataPtr, kBufferSize); + } + if (!propStream) { propStreamSpec = new CBufPtrSeqOutStream; // CBenchmarkOutStream; @@ -1251,7 +1284,7 @@ HRESULT CEncoderInfo::Generate() /* in posix new thread uses same affinity as parent thread, so we don't need to send affinity to coder in posix */ UInt64 affMask; - #if !defined(_7ZIP_ST) && defined(_WIN32) + #if !defined(Z7_ST) && defined(_WIN32) { CCpuSet cpuSet; affMask = AffinityMode.GetAffinityMask(EncoderIndex, &cpuSet); @@ -1262,7 +1295,7 @@ HRESULT CEncoderInfo::Generate() // affMask <<= 3; // debug line: to test no affinity in coder; // affMask = 0; - RINOK(method.SetCoderProps_DSReduce_Aff(scp, &reduceSize, (affMask != 0 ? &affMask : NULL))); + RINOK(method.SetCoderProps_DSReduce_Aff(scp, &reduceSize, (affMask != 0 ? &affMask : NULL))) } else { @@ -1274,7 +1307,7 @@ HRESULT CEncoderInfo::Generate() coder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProps); if (writeCoderProps) { - RINOK(writeCoderProps->WriteCoderProperties(propStream)); + RINOK(writeCoderProps->WriteCoderProperties(propStream)) } { @@ -1282,7 +1315,7 @@ HRESULT CEncoderInfo::Generate() coder.QueryInterface(IID_ICryptoSetPassword, &sp); if (sp) { - RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw))); + RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw))) // we must call encoding one time to calculate password key for key cache. // it must be after WriteCoderProperties! @@ -1304,7 +1337,7 @@ HRESULT CEncoderInfo::Generate() CMyComPtr<ISequentialOutStream> crcStream = crcStreamSpec; crcStreamSpec->Init(); - RINOK(_encoder->Code(inStream, crcStream, 0, 0, NULL)); + RINOK(_encoder->Code(inStream, crcStream, NULL, NULL, NULL)) } } } @@ -1314,19 +1347,22 @@ HRESULT CEncoderInfo::Generate() } -static void My_FilterBench(ICompressFilter *filter, Byte *data, size_t size) +static void My_FilterBench(ICompressFilter *filter, Byte *data, size_t size, UInt32 *crc) { while (size != 0) { - UInt32 cur = (UInt32)1 << 31; + UInt32 cur = crc ? 1 << 17 : 1 << 24; if (cur > size) cur = (UInt32)size; UInt32 processed = filter->Filter(data, cur); - data += processed; - // if (processed > size) (in AES filter), we must fill last block with zeros. - // but it is not important for benchmark. So we just copy that data without filtering. + /* if (processed > size) (in AES filter), we must fill last block with zeros. + but it is not important for benchmark. So we just copy that data without filtering. + if (processed == 0) then filter can't process more */ if (processed > size || processed == 0) - break; + processed = (UInt32)size; + if (crc) + *crc = CrcUpdate(*crc, data, processed); + data += processed; size -= processed; } } @@ -1336,11 +1372,11 @@ HRESULT CEncoderInfo::Encode() { // printf("\nCEncoderInfo::Generate\n"); - RINOK(Generate()); + RINOK(Generate()) // printf("\n2222\n"); - #ifndef _7ZIP_ST + #ifndef Z7_ST if (Common) { Results[0] = S_OK; @@ -1375,7 +1411,7 @@ HRESULT CEncoderInfo::Encode() if (cp) { - RINOK(Set_Key_and_IV(cp)); + RINOK(Set_Key_and_IV(cp)) } compressedSize = 0; @@ -1384,20 +1420,32 @@ HRESULT CEncoderInfo::Encode() // CBenchmarkOutStream *outStreamSpec = this->outStreamSpec; UInt64 prev = 0; - const UInt32 mask = (CheckCrc_Enc ? 0 : 0xFFF); - bool useCrc = (mask < NumIterations); + + const UInt32 mask = (CheckCrc_Enc ? 0 : 0xFFFF); + const bool useCrc = (mask < NumIterations); bool crcPrev_defined = false; UInt32 crcPrev = 0; - UInt64 i = NumIterations; + + bool useRealData_Enc = UseRealData_Enc; + bool data_Was_Changed = false; + if (useRealData_Enc) + { + /* we want memcpy() for each iteration including first iteration. + So results will be equal for different number of iterations */ + data_Was_Changed = true; + } + + const UInt64 numIterations = NumIterations; + UInt64 i = numIterations; // printCallback->NewLine(); while (i != 0) { i--; - if (printCallback && bi.UnpackSize - prev >= (1 << 24)) + if (printCallback && bi.UnpackSize - prev >= (1 << 26)) { - RINOK(printCallback->CheckBreak()); prev = bi.UnpackSize; + RINOK(printCallback->CheckBreak()) } /* @@ -1411,21 +1459,25 @@ HRESULT CEncoderInfo::Encode() if (_encoderFilter) { - // if (needRealData) - memcpy((Byte *)*outStreamSpec, uncompressedDataPtr, kBufferSize); + Byte *filterData = rgCopy; + if (i == numIterations - 1 || calcCrc || useRealData_Enc) + { + filterData = (Byte *)*outStreamSpec; + if (data_Was_Changed) + memcpy(filterData, uncompressedDataPtr, kBufferSize); + data_Was_Changed = true; + } _encoderFilter->Init(); - My_FilterBench(_encoderFilter, (Byte *)*outStreamSpec, kBufferSize); if (calcCrc) - { outStreamSpec->InitCrc(); - outStreamSpec->Calc((Byte *)*outStreamSpec, kBufferSize); - } + My_FilterBench(_encoderFilter, filterData, kBufferSize, + calcCrc ? &outStreamSpec->Crc : NULL); } else { outStreamSpec->Init(true, calcCrc); // write real data for speed consistency at any number of iterations inStreamSpec->Init(uncompressedDataPtr, kBufferSize); - RINOK(_encoder->Code(inStream, outStream, NULL, NULL, progressInfo[0])); + RINOK(_encoder->Code(inStream, outStream, NULL, NULL, progressInfo[0])) if (!inStreamSpec->WasFinished()) return E_FAIL; if (compressedSize != outStreamSpec->Pos) @@ -1461,7 +1513,7 @@ HRESULT CEncoderInfo::Encode() info.PackSize = compressedSize; // printf("\n%7d\n", encoder.compressedSize); - RINOK(callback->SetEncodeResult(info, true)); + RINOK(callback->SetEncodeResult(info, true)) printCallback->NewLine(); } */ @@ -1501,13 +1553,13 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) pi->BenchInfo.UnpackSize = 0; pi->BenchInfo.PackSize = 0; - #ifndef _7ZIP_ST + #ifndef Z7_ST { CMyComPtr<ICompressSetCoderMt> setCoderMt; coder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt); if (setCoderMt) { - RINOK(setCoderMt->SetNumberOfThreads(NumDecoderSubThreads)); + RINOK(setCoderMt->SetNumberOfThreads(NumDecoderSubThreads)) } } #endif @@ -1517,7 +1569,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) if (scp) { const UInt64 reduceSize = _uncompressedDataSize; - RINOK(_method.SetCoderProps(scp, &reduceSize)); + RINOK(_method.SetCoderProps(scp, &reduceSize)) } CMyComPtr<ICryptoProperties> cp; @@ -1528,7 +1580,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) RINOK(setDecProps->SetDecoderProperties2( /* (const Byte *)*propStreamSpec, */ propsData, - (UInt32)propStreamSpec->GetPos())); + (UInt32)propStreamSpec->GetPos())) } { @@ -1536,7 +1588,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) coder.QueryInterface(IID_ICryptoSetPassword, &sp); if (sp) { - RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw))); + RINOK(sp->CryptoSetPassword(_psw, sizeof(_psw))) } } @@ -1544,7 +1596,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) if (cp) { - RINOK(Set_Key_and_IV(cp)); + RINOK(Set_Key_and_IV(cp)) } CMyComPtr<ICompressSetFinishMode> setFinishMode; @@ -1559,32 +1611,38 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) decoder->QueryInterface(IID_ICompressSetFinishMode, (void **)&setFinishMode); } - const UInt64 numIterations = this->NumIterations; - const UInt32 mask = (CheckCrc_Dec ? 0 : 0xFFF); + const UInt64 numIterations = NumIterations; + const E_CheckCrcMode checkCrcMode = CheckCrcMode_Dec; for (UInt64 i = 0; i < numIterations; i++) { - if (printCallback && pi->BenchInfo.UnpackSize - prev >= (1 << 24)) + if (printCallback && pi->BenchInfo.UnpackSize - prev >= (1 << 26)) { - RINOK(printCallback->CheckBreak()); + RINOK(printCallback->CheckBreak()) prev = pi->BenchInfo.UnpackSize; } const UInt64 outSize = kBufferSize; - bool calcCrc = false; - if (((UInt32)i & mask) == 0) - calcCrc = true; + bool calcCrc = (checkCrcMode != k_CheckCrcMode_Never); + crcOutStreamSpec->Init(); - + if (_decoderFilter) { - if (calcCrc) // for pure filter speed test without multi-iteration consistency - // if (needRealData) - memcpy((Byte *)rgCopy, (const Byte *)*outStreamSpec, compressedSize); - _decoderFilter->Init(); - My_FilterBench(_decoderFilter, (Byte *)rgCopy, compressedSize); + Byte *filterData = (Byte *)*outStreamSpec; if (calcCrc) - crcOutStreamSpec->Calc((const Byte *)rgCopy, compressedSize); + { + calcCrc = (i == 0); + if (checkCrcMode == k_CheckCrcMode_Always) + { + calcCrc = true; + memcpy((Byte *)rgCopy, (const Byte *)*outStreamSpec, compressedSize); + filterData = rgCopy; + } + } + _decoderFilter->Init(); + My_FilterBench(_decoderFilter, filterData, compressedSize, + calcCrc ? &crcOutStreamSpec->Crc : NULL); } else { @@ -1593,10 +1651,10 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) if (setFinishMode) { - RINOK(setFinishMode->SetFinishMode(BoolToUInt(true))); + RINOK(setFinishMode->SetFinishMode(BoolToUInt(true))) } - RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex])); + RINOK(decoder->Code(inStream, crcOutStream, NULL, &outSize, progressInfo[decoderIndex])) if (setFinishMode) { @@ -1609,7 +1667,7 @@ HRESULT CEncoderInfo::Decode(UInt32 decoderIndex) if (getInStreamProcessedSize) { UInt64 processed; - RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&processed)); + RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&processed)) if (processed != compressedSize) return S_FALSE; } @@ -1652,7 +1710,7 @@ static UInt64 GetNumIterations(UInt64 numCommands, UInt64 complexInCommands) -#ifndef _7ZIP_ST +#ifndef Z7_ST // ---------- CBenchThreadsFlusher ---------- @@ -1696,7 +1754,7 @@ WRes CBenchThreadsFlusher::StartAndWait(bool exitMode) return res; } -#endif // _7ZIP_ST +#endif // Z7_ST @@ -1714,7 +1772,7 @@ static void SetPseudoRand(Byte *data, size_t size, UInt32 startValue) static HRESULT MethodBench( DECL_EXTERNAL_CODECS_LOC_VARS UInt64 complexInCommands, - #ifndef _7ZIP_ST + #ifndef Z7_ST bool oldLzmaBenchMode, UInt32 numThreads, const CAffinityMode *affinityMode, @@ -1731,10 +1789,11 @@ static HRESULT MethodBench( COneMethodInfo method = method2; UInt64 methodId; UInt32 numStreams; + bool isFilter; const int codecIndex = FindMethod_Index( EXTERNAL_CODECS_LOC_VARS method.MethodName, true, - methodId, numStreams); + methodId, numStreams, isFilter); if (codecIndex < 0) return E_NOTIMPL; if (numStreams != 1) @@ -1743,7 +1802,7 @@ static HRESULT MethodBench( UInt32 numEncoderThreads = 1; UInt32 numSubDecoderThreads = 1; - #ifndef _7ZIP_ST + #ifndef Z7_ST numEncoderThreads = numThreads; if (oldLzmaBenchMode) @@ -1759,7 +1818,7 @@ static HRESULT MethodBench( } } - bool mtEncMode = (numEncoderThreads > 1) || affinityMode->NeedAffinity(); + const bool mtEncMode = (numEncoderThreads > 1) || affinityMode->NeedAffinity(); #endif @@ -1771,10 +1830,10 @@ static HRESULT MethodBench( for (i = 0; i < numEncoderThreads; i++) { CEncoderInfo &encoder = encoders[i]; - encoder.callback = (i == 0) ? callback : 0; + encoder.callback = (i == 0) ? callback : NULL; encoder.printCallback = printCallback; - #ifndef _7ZIP_ST + #ifndef Z7_ST encoder.EncoderIndex = i; encoder.NumEncoderInternalThreads = numSubDecoderThreads; encoder.AffinityMode = *affinityMode; @@ -1794,15 +1853,12 @@ static HRESULT MethodBench( { CCreatedCoder cod; - RINOK(CreateCoder_Index(EXTERNAL_CODECS_LOC_VARS (unsigned)codecIndex, true, encoder._encoderFilter, cod)); + RINOK(CreateCoder_Index(EXTERNAL_CODECS_LOC_VARS (unsigned)codecIndex, true, encoder._encoderFilter, cod)) encoder._encoder = cod.Coder; if (!encoder._encoder && !encoder._encoderFilter) return E_NOTIMPL; } - encoder.CheckCrc_Enc = (benchProps->EncComplex) > 30; - encoder.CheckCrc_Dec = (benchProps->DecComplexCompr + benchProps->DecComplexUnc) > 30; - SetPseudoRand(encoder._iv, sizeof(encoder._iv), 17); SetPseudoRand(encoder._key, sizeof(encoder._key), 51); SetPseudoRand(encoder._psw, sizeof(encoder._psw), 123); @@ -1811,11 +1867,27 @@ static HRESULT MethodBench( { CCreatedCoder cod; CMyComPtr<ICompressCoder> &decoder = encoder._decoders[j]; - RINOK(CreateCoder_Id(EXTERNAL_CODECS_LOC_VARS methodId, false, encoder._decoderFilter, cod)); + RINOK(CreateCoder_Id(EXTERNAL_CODECS_LOC_VARS methodId, false, encoder._decoderFilter, cod)) decoder = cod.Coder; if (!encoder._decoderFilter && !decoder) return E_NOTIMPL; } + + encoder.UseRealData_Enc = + encoder.CheckCrc_Enc = (benchProps->EncComplex) > 30; + + encoder.CheckCrcMode_Dec = k_CheckCrcMode_Always; + if (benchProps->DecComplexCompr + + benchProps->DecComplexUnc <= 30) + encoder.CheckCrcMode_Dec = + k_CheckCrcMode_FirstPass; // for filters + // k_CheckCrcMode_Never; // for debug + // k_CheckCrcMode_Always; // for debug + if (fileData) + { + encoder.UseRealData_Enc = true; + encoder.CheckCrcMode_Dec = k_CheckCrcMode_Always; + } } UInt32 crc = 0; @@ -1837,7 +1909,7 @@ static HRESULT MethodBench( status.Res = S_OK; status.EncodeMode = true; - #ifndef _7ZIP_ST + #ifndef Z7_ST CBenchThreadsFlusher encoderFlusher; if (mtEncMode) { @@ -1853,7 +1925,7 @@ static HRESULT MethodBench( for (i = 0; i < numEncoderThreads; i++) { CEncoderInfo &encoder = encoders[i]; - encoder.NumIterations = GetNumIterations(benchProps->GeComprCommands(uncompressedDataSize), complexInCommands); + encoder.NumIterations = GetNumIterations(benchProps->GetNumCommands_Enc(uncompressedDataSize), complexInCommands); // encoder.NumIterations = 3; encoder.Salt = g_CrcTable[i & 0xFF]; encoder.Salt ^= (g_CrcTable[(i >> 8) & 0xFF] << 3); @@ -1877,7 +1949,7 @@ static HRESULT MethodBench( bpi->BenchInfo.NumIterations = numEncoderThreads; } - #ifndef _7ZIP_ST + #ifndef Z7_ST if (mtEncMode) { #ifdef USE_ALLOCA @@ -1885,6 +1957,7 @@ static HRESULT MethodBench( #endif encoder.Common = &encoderFlusher.Common; + encoder.IsGlobalMtMode = numEncoderThreads > 1; RINOK(encoder.CreateEncoderThread()) } #endif @@ -1892,35 +1965,35 @@ static HRESULT MethodBench( if (printCallback) { - RINOK(printCallback->CheckBreak()); + RINOK(printCallback->CheckBreak()) } - #ifndef _7ZIP_ST + #ifndef Z7_ST if (mtEncMode) { for (i = 0; i < numEncoderThreads; i++) { CEncoderInfo &encoder = encoders[i]; - WRes wres = encoder.ReadyEvent.Lock(); + const WRes wres = encoder.ReadyEvent.Lock(); if (wres != 0) return HRESULT_FROM_WIN32(wres); - RINOK(encoder.Results[0]); + RINOK(encoder.Results[0]) } CBenchProgressInfo *bpi = encoders[0].progressInfoSpec[0]; bpi->SetStartTime(); - WRes wres = encoderFlusher.StartAndWait(); + const WRes wres = encoderFlusher.StartAndWait(); if (status.Res == 0 && wres != 0) return HRESULT_FROM_WIN32(wres); } else #endif { - RINOK(encoders[0].Encode()); + RINOK(encoders[0].Encode()) } - RINOK(status.Res); + RINOK(status.Res) CBenchInfo info; @@ -1931,13 +2004,13 @@ static HRESULT MethodBench( for (i = 0; i < numEncoderThreads; i++) { - CEncoderInfo &encoder = encoders[i]; + const CEncoderInfo &encoder = encoders[i]; info.UnpackSize += encoder.kBufferSize; info.PackSize += encoder.compressedSize; // printf("\n%7d\n", encoder.compressedSize); } - RINOK(callback->SetEncodeResult(info, true)); + RINOK(callback->SetEncodeResult(info, true)) @@ -1948,7 +2021,7 @@ static HRESULT MethodBench( status.EncodeMode = false; const UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads; - #ifndef _7ZIP_ST + #ifndef Z7_ST const bool mtDecoderMode = (numDecoderThreads > 1) || affinityMode->NeedAffinity(); #endif @@ -1957,7 +2030,7 @@ static HRESULT MethodBench( CEncoderInfo &encoder = encoders[i]; /* - #ifndef _7ZIP_ST + #ifndef Z7_ST // encoder.affinityMode = *affinityMode; if (encoder.NumEncoderInternalThreads != 1) encoder.AffinityMode.DivideNum = encoder.NumEncoderInternalThreads; @@ -1967,7 +2040,11 @@ static HRESULT MethodBench( if (i == 0) { - encoder.NumIterations = GetNumIterations(benchProps->GeDecomprCommands(encoder.compressedSize, encoder.kBufferSize), complexInCommands); + encoder.NumIterations = GetNumIterations( + benchProps->GetNumCommands_Dec( + encoder.compressedSize, + encoder.kBufferSize), + complexInCommands); CBenchProgressInfo *bpi = encoder.progressInfoSpec[0]; bpi->Callback = callback; bpi->BenchInfo.NumIterations = numDecoderThreads; @@ -1976,7 +2053,7 @@ static HRESULT MethodBench( else encoder.NumIterations = encoders[0].NumIterations; - #ifndef _7ZIP_ST + #ifndef Z7_ST { int numSubThreads = method.Get_NumThreads(); encoder.NumDecoderSubThreads = (numSubThreads <= 0) ? 1 : (unsigned)numSubThreads; @@ -1985,22 +2062,22 @@ static HRESULT MethodBench( { for (UInt32 j = 0; j < numSubDecoderThreads; j++) { - HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0) + const HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0) #ifdef USE_ALLOCA , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF #endif ); - RINOK(res); + RINOK(res) } } else #endif { - RINOK(encoder.Decode(0)); + RINOK(encoder.Decode(0)) } } - #ifndef _7ZIP_ST + #ifndef Z7_ST if (mtDecoderMode) { WRes wres = 0; @@ -2009,26 +2086,26 @@ static HRESULT MethodBench( for (UInt32 j = 0; j < numSubDecoderThreads; j++) { CEncoderInfo &encoder = encoders[i]; - WRes wres2 = encoder.thread[j]. + const WRes wres2 = encoder.thread[j]. // Wait(); // later we can get thread times from thread in UNDER_CE Wait_Close(); if (wres == 0 && wres2 != 0) wres = wres2; - HRESULT res2 = encoder.Results[j]; + const HRESULT res2 = encoder.Results[j]; if (res == 0 && res2 != 0) res = res2; } if (wres != 0) return HRESULT_FROM_WIN32(wres); - RINOK(res); + RINOK(res) } - #endif // _7ZIP_ST + #endif // Z7_ST - RINOK(status.Res); + RINOK(status.Res) encoders[0].progressInfoSpec[0]->SetFinishTime(info); /* - #ifndef _7ZIP_ST + #ifndef Z7_ST #ifdef UNDER_CE if (mtDecoderMode) for (i = 0; i < numEncoderThreads; i++) @@ -2048,13 +2125,13 @@ static HRESULT MethodBench( for (i = 0; i < numEncoderThreads; i++) { - CEncoderInfo &encoder = encoders[i]; + const CEncoderInfo &encoder = encoders[i]; info.UnpackSize += encoder.kBufferSize; info.PackSize += encoder.compressedSize; } - // RINOK(callback->SetDecodeResult(info, false)); // why we called before 21.03 ?? - RINOK(callback->SetDecodeResult(info, true)); + // RINOK(callback->SetDecodeResult(info, false)) // why we called before 21.03 ?? + RINOK(callback->SetDecodeResult(info, true)) return S_OK; } @@ -2234,7 +2311,7 @@ HRESULT CCrcInfo_Base::CrcProcess(UInt64 numIterations, if (cur - prev >= ((UInt32)1 << 30)) { prev = cur; - RINOK(callback->CheckBreak()); + RINOK(callback->CheckBreak()) } } } @@ -2266,7 +2343,7 @@ static UInt32 CountCpuFreq(UInt32 sum, UInt32 num, UInt32 val) EXTERN_C_END -#ifndef _7ZIP_ST +#ifndef Z7_ST struct CBaseThreadInfo { @@ -2300,12 +2377,12 @@ static THREAD_FUNC_DECL FreqThreadFunction(void *param) { p->CallbackRes = p->Callback->CheckBreak(); if (p->CallbackRes != S_OK) - return 0; + break; } sum = CountCpuFreq(sum, p->Size, g_BenchCpuFreqTemp); } p->ValRes = sum; - return 0; + return THREAD_FUNC_RET_ZERO; } struct CFreqThreads @@ -2349,7 +2426,7 @@ struct CCrcInfo: public CBaseThreadInfo HRESULT Res; UInt32 CheckSum_Res; - #ifndef _7ZIP_ST + #ifndef Z7_ST NSynchronization::CManualResetEvent ReadyEvent; UInt32 ThreadIndex; CBenchSyncCommon *Common; @@ -2433,7 +2510,7 @@ static THREAD_FUNC_DECL CrcThreadFunction(void *param) alloca(p->AllocaSize); #endif p->Process(); - return 0; + return THREAD_FUNC_RET_ZERO; } @@ -2480,7 +2557,7 @@ WRes CCrcThreads::StartAndWait(bool exitMode) static UInt32 CrcCalc1(const Byte *buf, size_t size) { - UInt32 crc = CRC_INIT_VAL;; + UInt32 crc = CRC_INIT_VAL; for (size_t i = 0; i < size; i++) crc = CRC_UPDATE_BYTE(crc, buf[i]); return CRC_GET_DIGEST(crc); @@ -2522,9 +2599,9 @@ struct CBenchMethod { unsigned Weight; unsigned DictBits; - UInt32 EncComplex; - UInt32 DecComplexCompr; - UInt32 DecComplexUnc; + Int32 EncComplex; + Int32 DecComplexCompr; + Int32 DecComplexUnc; const char *Name; // unsigned KeySize; }; @@ -2563,6 +2640,9 @@ static const CBenchMethod g_Bench[] = // { 10, 22, 1655, 0, 1830, "PPMDZip:x5" }, { 10, 22, 1655, 0, 1830, "PPMD:x5" }, + // { 2, 0, -16, 0, -16, "Swap2" }, + { 2, 0, -16, 0, -16, "Swap4" }, + // { 2, 0, 3, 0, 4, "Delta:1" }, // { 2, 0, 3, 0, 4, "Delta:2" }, // { 2, 0, 3, 0, 4, "Delta:3" }, @@ -2570,8 +2650,9 @@ static const CBenchMethod g_Bench[] = // { 2, 0, 3, 0, 4, "Delta:8" }, // { 2, 0, 3, 0, 4, "Delta:32" }, - { 2, 0, 4, 0, 4, "BCJ" }, - + { 2, 0, 2, 0, 2, "BCJ" }, + { 2, 0, 1, 0, 1, "ARM64" }, + // { 10, 0, 18, 0, 18, "AES128CBC:1" }, // { 10, 0, 21, 0, 21, "AES192CBC:1" }, { 10, 0, 24, 0, 24, "AES256CBC:1" }, @@ -2607,11 +2688,13 @@ struct CBenchHash // #define ARM_CRC_MUL 100 #define ARM_CRC_MUL 1 +#define k_Hash_Complex_Mult 256 + static const CBenchHash g_Hash[] = { - { 1, 1820, 0x21e207bb, "CRC32:1" }, - { 10, 558, 0x21e207bb, "CRC32:4" }, - { 10, 339, 0x21e207bb, "CRC32:8" } , + // { 1, 1820, 0x21e207bb, "CRC32:1" }, + // { 10, 558, 0x21e207bb, "CRC32:4" }, + { 20, 339, 0x21e207bb, "CRC32:8" } , { 2, 128 *ARM_CRC_MUL, 0x21e207bb, "CRC32:32" }, { 2, 64 *ARM_CRC_MUL, 0x21e207bb, "CRC32:64" }, { 10, 512, 0x41b901d1, "CRC64" }, @@ -2656,6 +2739,8 @@ static const unsigned kFieldSize_RU = 6; static const unsigned kFieldSize_Rating = 6; static const unsigned kFieldSize_EU = 5; static const unsigned kFieldSize_Effec = 5; +static const unsigned kFieldSize_CrcSpeed = 8; + static const unsigned kFieldSize_TotalSize = 4 + kFieldSize_Speed + kFieldSize_Usage + kFieldSize_RU + kFieldSize_Rating; static const unsigned kFieldSize_EUAndEffec = 2 + kFieldSize_EU + kFieldSize_Effec; @@ -2830,7 +2915,7 @@ AString GetProcessThreadsInfo(const NSystem::CProcessAffinity &ti) } -#ifdef _7ZIP_LARGE_PAGES +#ifdef Z7_LARGE_PAGES #ifdef _WIN32 extern bool g_LargePagesMode; @@ -2875,7 +2960,7 @@ static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString, f.Print(" ?"); f.Print(" MB"); - #ifdef _7ZIP_LARGE_PAGES + #ifdef Z7_LARGE_PAGES { AString s; Add_LargePages_String(s); @@ -2890,30 +2975,34 @@ static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString, -struct CBenchCallbackToPrint: public IBenchCallback +struct CBenchCallbackToPrint Z7_final: public IBenchCallback { - CBenchProps BenchProps; - CTotalBenchRes EncodeRes; - CTotalBenchRes DecodeRes; - IBenchPrintCallback *_file; - UInt64 DictSize; - + bool NeedPrint; bool Use2Columns; - unsigned NameFieldSize; - bool ShowFreq; - UInt64 CpuFreq; + unsigned NameFieldSize; unsigned EncodeWeight; unsigned DecodeWeight; + UInt64 CpuFreq; + UInt64 DictSize; + + IBenchPrintCallback *_file; + CBenchProps BenchProps; + CTotalBenchRes EncodeRes; + CTotalBenchRes DecodeRes; + + CBenchInfo BenchInfo_Results[2]; + CBenchCallbackToPrint(): + NeedPrint(true), Use2Columns(false), - NameFieldSize(0), ShowFreq(false), - CpuFreq(0), + NameFieldSize(0), EncodeWeight(1), - DecodeWeight(1) + DecodeWeight(1), + CpuFreq(0) {} void Init() { EncodeRes.Init(); DecodeRes.Init(); } @@ -2921,8 +3010,8 @@ struct CBenchCallbackToPrint: public IBenchCallback void NewLine(); HRESULT SetFreq(bool showFreq, UInt64 cpuFreq); - HRESULT SetEncodeResult(const CBenchInfo &info, bool final); - HRESULT SetDecodeResult(const CBenchInfo &info, bool final); + HRESULT SetEncodeResult(const CBenchInfo &info, bool final) Z7_override; + HRESULT SetDecodeResult(const CBenchInfo &info, bool final) Z7_override; }; HRESULT CBenchCallbackToPrint::SetFreq(bool showFreq, UInt64 cpuFreq) @@ -2934,10 +3023,13 @@ HRESULT CBenchCallbackToPrint::SetFreq(bool showFreq, UInt64 cpuFreq) HRESULT CBenchCallbackToPrint::SetEncodeResult(const CBenchInfo &info, bool final) { - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) if (final) + BenchInfo_Results[0] = info; + if (final) + if (NeedPrint) { - UInt64 rating = BenchProps.GetCompressRating(DictSize, info.GlobalTime, info.GlobalFreq, info.UnpackSize * info.NumIterations); + const UInt64 rating = BenchProps.GetRating_Enc(DictSize, info.GlobalTime, info.GlobalFreq, info.UnpackSize * info.NumIterations); PrintResults(_file, info, EncodeWeight, rating, ShowFreq, CpuFreq, &EncodeRes); @@ -2951,10 +3043,13 @@ static const char * const kSep = " | "; HRESULT CBenchCallbackToPrint::SetDecodeResult(const CBenchInfo &info, bool final) { - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) + if (final) + BenchInfo_Results[1] = info; if (final) + if (NeedPrint) { - UInt64 rating = BenchProps.GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations); + const UInt64 rating = BenchProps.GetRating_Dec(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations); if (Use2Columns) _file->Print(kSep); else @@ -2996,10 +3091,22 @@ static void PrintRight(IBenchPrintCallback &f, const char *s, unsigned size) f.Print(s); } + +static bool DoesWildcardMatchName_NoCase(const AString &mask, const char *name) +{ + UString wildc = GetUnicodeString(mask); + UString bname = GetUnicodeString(name); + wildc.MakeLower_Ascii(); + bname.MakeLower_Ascii(); + return DoesWildcardMatchName(wildc, bname); +} + + static HRESULT TotalBench( DECL_EXTERNAL_CODECS_LOC_VARS + const COneMethodInfo &methodMask, UInt64 complexInCommands, - #ifndef _7ZIP_ST + #ifndef Z7_ST UInt32 numThreads, const CAffinityMode *affinityMode, #endif @@ -3008,9 +3115,11 @@ static HRESULT TotalBench( const Byte *fileData, IBenchPrintCallback *printCallback, CBenchCallbackToPrint *callback) { - for (unsigned i = 0; i < ARRAY_SIZE(g_Bench); i++) + for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++) { const CBenchMethod &bench = g_Bench[i]; + if (!DoesWildcardMatchName_NoCase(methodMask.MethodName, bench.Name)) + continue; PrintLeft(*callback->_file, bench.Name, kFieldSize_Name); { unsigned keySize = 32; @@ -3025,7 +3134,7 @@ static HRESULT TotalBench( COneMethodInfo method; NCOM::CPropVariant propVariant; propVariant = bench.Name; - RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant)); + RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant)) size_t unpackSize2 = unpackSize; if (!forceUnpackSize && bench.DictBits == 0) @@ -3034,10 +3143,10 @@ static HRESULT TotalBench( callback->EncodeWeight = bench.Weight; callback->DecodeWeight = bench.Weight; - HRESULT res = MethodBench( + const HRESULT res = MethodBench( EXTERNAL_CODECS_LOC_VARS complexInCommands, - #ifndef _7ZIP_ST + #ifndef Z7_ST false, numThreads, affinityMode, #endif method, @@ -3054,7 +3163,7 @@ static HRESULT TotalBench( } else { - RINOK(res); + RINOK(res) } callback->NewLine(); @@ -3080,7 +3189,7 @@ struct CFreqBench {} HRESULT FreqBench(IBenchPrintCallback *_file - #ifndef _7ZIP_ST + #ifndef Z7_ST , const CAffinityMode *affinityMode #endif ); @@ -3088,7 +3197,7 @@ struct CFreqBench HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file - #ifndef _7ZIP_ST + #ifndef Z7_ST , const CAffinityMode *affinityMode #endif ) @@ -3100,7 +3209,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file if (numThreads == 0) numThreads = 1; - #ifdef _7ZIP_ST + #ifdef Z7_ST numThreads = 1; #endif @@ -3117,7 +3226,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file CBenchInfoCalc progressInfoSpec; - #ifndef _7ZIP_ST + #ifndef Z7_ST bool mtMode = (numThreads > 1) || affinityMode->NeedAffinity(); @@ -3150,7 +3259,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file return HRESULT_FROM_WIN32(wres); for (i = 0; i < numThreads; i++) { - RINOK(threads.Items[i].CallbackRes); + RINOK(threads.Items[i].CallbackRes) } } else @@ -3163,7 +3272,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file sum = CountCpuFreq(sum, numIterations2, g_BenchCpuFreqTemp); if (_file) { - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) } } res += sum; @@ -3172,7 +3281,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file if (res == 0x12345678) if (_file) { - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) } CBenchInfo info; @@ -3193,7 +3302,7 @@ HRESULT CFreqBench::FreqBench(IBenchPrintCallback *_file 0, // weight rating, showFreq, showFreq ? (specifiedFreq != 0 ? specifiedFreq : CpuFreqRes) : 0, NULL); - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) } return S_OK; @@ -3215,7 +3324,7 @@ static HRESULT CrcBench( const UInt32 *checkSum, const COneMethodInfo &method, IBenchPrintCallback *_file, - #ifndef _7ZIP_ST + #ifndef Z7_ST const CAffinityMode *affinityMode, #endif bool showRating, @@ -3225,7 +3334,7 @@ static HRESULT CrcBench( if (numThreads == 0) numThreads = 1; - #ifdef _7ZIP_ST + #ifdef Z7_ST numThreads = 1; #endif @@ -3249,14 +3358,14 @@ static HRESULT CrcBench( */ const size_t bsize = (bufferSize == 0 ? 1 : bufferSize); - UInt64 numIterations = complexInCommands * 256 / complexity / bsize; + UInt64 numIterations = complexInCommands * k_Hash_Complex_Mult / complexity / bsize; if (numIterations == 0) numIterations = 1; CBenchInfoCalc progressInfoSpec; CBenchInfo info; - #ifndef _7ZIP_ST + #ifndef Z7_ST bool mtEncMode = (numThreads > 1) || affinityMode->NeedAffinity(); if (mtEncMode) @@ -3275,14 +3384,14 @@ static HRESULT CrcBench( { CCrcInfo &ci = threads.Items[i]; AString name; - RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, ci.Hasher)); + RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, ci.Hasher)) if (!ci.Hasher) return E_NOTIMPL; CMyComPtr<ICompressSetCoderProperties> scp; ci.Hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp); if (scp) { - RINOK(method.SetCoderProps(scp)); + RINOK(method.SetCoderProps(scp)) } ci.Callback = _file; @@ -3320,7 +3429,7 @@ static HRESULT CrcBench( WRes wres = ci.ReadyEvent.Lock(); if (wres != 0) return HRESULT_FROM_WIN32(wres); - RINOK(ci.Res); + RINOK(ci.Res) } progressInfoSpec.SetStartTime(); @@ -3333,7 +3442,7 @@ static HRESULT CrcBench( for (i = 0; i < numThreads; i++) { - RINOK(threads.Items[i].Res); + RINOK(threads.Items[i].Res) if (i != 0) if (threads.Items[i].CheckSum_Res != threads.Items[i - 1].CheckSum_Res) @@ -3345,20 +3454,20 @@ static HRESULT CrcBench( { CMyComPtr<IHasher> hasher; AString name; - RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, hasher)); + RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS hashID, name, hasher)) if (!hasher) return E_NOTIMPL; CMyComPtr<ICompressSetCoderProperties> scp; hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp); if (scp) { - RINOK(method.SetCoderProps(scp)); + RINOK(method.SetCoderProps(scp)) } CCrcInfo_Base crcib; crcib.CreateLocalBuf = false; - RINOK(crcib.Generate(fileData, bufferSize)); + RINOK(crcib.Generate(fileData, bufferSize)) progressInfoSpec.SetStartTime(); - RINOK(crcib.CrcProcess(numIterations, checkSum, hasher, _file)); + RINOK(crcib.CrcProcess(numIterations, checkSum, hasher, _file)) progressInfoSpec.SetFinishTime(info); } @@ -3382,7 +3491,7 @@ static HRESULT CrcBench( benchWeight, rating, showFreq, cpuFreq, encodeRes); } - RINOK(_file->CheckBreak()); + RINOK(_file->CheckBreak()) } speed = info.GetSpeed(unpSizeThreads); @@ -3395,20 +3504,23 @@ static HRESULT CrcBench( static HRESULT TotalBench_Hash( DECL_EXTERNAL_CODECS_LOC_VARS + const COneMethodInfo &methodMask, UInt64 complexInCommands, UInt32 numThreads, size_t bufSize, const Byte *fileData, IBenchPrintCallback *printCallback, CBenchCallbackToPrint *callback, - #ifndef _7ZIP_ST + #ifndef Z7_ST const CAffinityMode *affinityMode, #endif CTotalBenchRes *encodeRes, bool showFreq, UInt64 cpuFreq) { - for (unsigned i = 0; i < ARRAY_SIZE(g_Hash); i++) + for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Hash); i++) { const CBenchHash &bench = g_Hash[i]; + if (!DoesWildcardMatchName_NoCase(methodMask.MethodName, bench.Name)) + continue; PrintLeft(*callback->_file, bench.Name, kFieldSize_Name); // callback->BenchProps.DecComplexUnc = bench.DecComplexUnc; // callback->BenchProps.DecComplexCompr = bench.DecComplexCompr; @@ -3417,11 +3529,11 @@ static HRESULT TotalBench_Hash( COneMethodInfo method; NCOM::CPropVariant propVariant; propVariant = bench.Name; - RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant)); + RINOK(method.ParseMethodFromPROPVARIANT(UString(), propVariant)) UInt64 speed, usage; - HRESULT res = CrcBench( + const HRESULT res = CrcBench( EXTERNAL_CODECS_LOC_VARS complexInCommands, numThreads, bufSize, fileData, @@ -3430,7 +3542,7 @@ static HRESULT TotalBench_Hash( (!fileData && bufSize == (1 << kNumHashDictBits)) ? &bench.CheckSum : NULL, method, printCallback, - #ifndef _7ZIP_ST + #ifndef Z7_ST affinityMode, #endif true, // showRating @@ -3441,7 +3553,7 @@ static HRESULT TotalBench_Hash( } else { - RINOK(res); + RINOK(res) } callback->NewLine(); } @@ -3451,7 +3563,8 @@ static HRESULT TotalBench_Hash( struct CTempValues { UInt64 *Values; - CTempValues(UInt32 num) { Values = new UInt64[num]; } + CTempValues(): Values(NULL) {} + void Alloc(UInt32 num) { Values = new UInt64[num]; } ~CTempValues() { delete []Values; } }; @@ -3482,6 +3595,29 @@ static void Print_Usage_and_Threads(IBenchPrintCallback &f, UInt64 usage, UInt32 } +static void Print_Delimiter(IBenchPrintCallback &f) +{ + f.Print(" |"); +} + +static void Print_Pow(IBenchPrintCallback &f, unsigned pow) +{ + char s[16]; + ConvertUInt32ToString(pow, s); + unsigned pos = MyStringLen(s); + s[pos++] = ':'; + s[pos] = 0; + PrintLeft(f, s, kFieldSize_SmallName); // 4 +} + +static void Bench_BW_Print_Usage_Speed(IBenchPrintCallback &f, + UInt64 usage, UInt64 speed) +{ + PrintUsage(f, usage, kFieldSize_Usage); + PrintNumber(f, speed / 1000000, kFieldSize_CrcSpeed); +} + + HRESULT Bench( DECL_EXTERNAL_CODECS_LOC_VARS IBenchPrintCallback *printCallback, @@ -3500,7 +3636,7 @@ HRESULT Bench( NSystem::CProcessAffinity threadsInfo; threadsInfo.InitST(); - #ifndef _7ZIP_ST + #ifndef Z7_ST if (threadsInfo.Get() && threadsInfo.GetNumProcessThreads() != 0) numCPUs = threadsInfo.GetNumProcessThreads(); @@ -3533,7 +3669,7 @@ HRESULT Bench( UInt64 complexInCommands = kComplexInCommands; UInt32 numThreads_Start = 1; - #ifndef _7ZIP_ST + #ifndef Z7_ST CAffinityMode affinityMode; #endif @@ -3597,7 +3733,7 @@ HRESULT Bench( // (len == 0) is allowed. Also it's allowed if Alloc(0) returns NULL here - ALLOC_WITH_HRESULT(&fileDataBuffer, len); + ALLOC_WITH_HRESULT(&fileDataBuffer, len) use_fileData = true; { @@ -3616,7 +3752,7 @@ HRESULT Bench( if (name.IsEqualTo("time")) { - RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs)); + RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs)) needSetComplexity = true; testTimeMs *= 1000; continue; @@ -3624,7 +3760,7 @@ HRESULT Bench( if (name.IsEqualTo("timems")) { - RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs)); + RINOK(ParsePropToUInt32(UString(), propVariant, testTimeMs)) needSetComplexity = true; continue; } @@ -3632,7 +3768,7 @@ HRESULT Bench( if (name.IsEqualTo("tic")) { UInt32 v; - RINOK(ParsePropToUInt32(UString(), propVariant, v)); + RINOK(ParsePropToUInt32(UString(), propVariant, v)) if (v >= 64) return E_INVALIDARG; complexInCommands = (UInt64)1 << v; @@ -3644,7 +3780,7 @@ HRESULT Bench( isFixedDict = true; if (isCurrent_fixedDict || name.IsEqualTo("ds")) { - RINOK(ParsePropToUInt32(UString(), propVariant, startDicLog)); + RINOK(ParsePropToUInt32(UString(), propVariant, startDicLog)) if (startDicLog > 32) return E_INVALIDARG; startDicLog_Defined = true; @@ -3653,17 +3789,17 @@ HRESULT Bench( if (name.IsEqualTo("mts")) { - RINOK(ParsePropToUInt32(UString(), propVariant, numThreads_Start)); + RINOK(ParsePropToUInt32(UString(), propVariant, numThreads_Start)) continue; } if (name.IsEqualTo("af")) { UInt32 bundle; - RINOK(ParsePropToUInt32(UString(), propVariant, bundle)); + RINOK(ParsePropToUInt32(UString(), propVariant, bundle)) if (bundle > 0 && bundle < numCPUs) { - #ifndef _7ZIP_ST + #ifndef Z7_ST affinityMode.SetLevels(numCPUs, 2); affinityMode.NumBundleThreads = bundle; #endif @@ -3674,7 +3810,7 @@ HRESULT Bench( if (name.IsEqualTo("freq")) { UInt32 freq32 = 0; - RINOK(ParsePropToUInt32(UString(), propVariant, freq32)); + RINOK(ParsePropToUInt32(UString(), propVariant, freq32)) if (freq32 == 0) return E_INVALIDARG; specifiedFreq = (UInt64)freq32 * 1000000; @@ -3691,7 +3827,7 @@ HRESULT Bench( if (name.IsPrefixedBy_Ascii_NoCase("mt")) { - UString s = name.Ptr(2); + const UString s = name.Ptr(2); if (s.IsEqualTo("*") || (s.IsEmpty() && propVariant.vt == VT_BSTR @@ -3700,13 +3836,13 @@ HRESULT Bench( multiThreadTests = true; continue; } - #ifndef _7ZIP_ST - RINOK(ParseMtProp(s, propVariant, numCPUs, numThreadsSpecified)); + #ifndef Z7_ST + RINOK(ParseMtProp(s, propVariant, numCPUs, numThreadsSpecified)) #endif continue; } - RINOK(method.ParseMethodFromPROPVARIANT(name, propVariant)); + RINOK(method.ParseMethodFromPROPVARIANT(name, propVariant)) } } @@ -3714,13 +3850,13 @@ HRESULT Bench( { AString s; - #ifndef _WIN32 + #ifndef _WIN32 s += "Compiler: "; GetCompiler(s); printCallback->Print(s); printCallback->NewLine(); s.Empty(); - #endif + #endif GetSystemInfoText(s); printCallback->Print(s); @@ -3744,7 +3880,7 @@ HRESULT Bench( for (int jj = 0;; jj++) { if (printCallback) - RINOK(printCallback->CheckBreak()); + RINOK(printCallback->CheckBreak()) UInt64 start = ::GetTimeCount(); UInt32 sum = (UInt32)start; @@ -3776,7 +3912,7 @@ HRESULT Bench( } if (freqCallback) { - RINOK(freqCallback->AddCpuFreq(1, hz, kBenchmarkUsageMult)); + RINOK(freqCallback->AddCpuFreq(1, hz, kBenchmarkUsageMult)) } if (jj >= 1) @@ -3806,7 +3942,7 @@ HRESULT Bench( } if (freqCallback) { - RINOK(freqCallback->FreqsFinished(1)); + RINOK(freqCallback->FreqsFinished(1)) } } @@ -3830,17 +3966,24 @@ HRESULT Bench( printCallback->Print(s); printCallback->Print("T CPU Freq (MHz):"); } - UInt64 numMilCommands = 1 << 10; + UInt64 numMilCommands = 1 << + #ifdef _DEBUG + 7; + #else + 10; + #endif + if (specifiedFreq != 0) { while (numMilCommands > 1 && specifiedFreq < (numMilCommands * 1000000)) numMilCommands >>= 1; } - for (int jj = 0;; jj++) + // for (int jj = 0;; jj++) + for (;;) { if (printCallback) - RINOK(printCallback->CheckBreak()); + RINOK(printCallback->CheckBreak()) { // PrintLeft(f, "CPU", kFieldSize_Name); @@ -3855,16 +3998,16 @@ HRESULT Bench( fb.showFreq = true; fb.specifiedFreq = 1; - HRESULT res = fb.FreqBench(NULL /* printCallback */ - #ifndef _7ZIP_ST + const HRESULT res = fb.FreqBench(NULL /* printCallback */ + #ifndef Z7_ST , &affinityMode #endif ); - RINOK(res); + RINOK(res) if (freqCallback) { - RINOK(freqCallback->AddCpuFreq(numThreads, fb.CpuFreqRes, fb.UsageRes)); + RINOK(freqCallback->AddCpuFreq(numThreads, fb.CpuFreqRes, fb.UsageRes)) } if (printCallback) @@ -3889,7 +4032,7 @@ HRESULT Bench( } // if (jj >= 1) { - bool needStop = (numMilCommands >= (1 << + const bool needStop = (numMilCommands >= (1 << #ifdef _DEBUG 7 #else @@ -3903,7 +4046,7 @@ HRESULT Bench( } if (freqCallback) { - RINOK(freqCallback->FreqsFinished(numThreads)); + RINOK(freqCallback->FreqsFinished(numThreads)) } } @@ -3923,10 +4066,12 @@ HRESULT Bench( UInt64 dict = (UInt64)1 << startDicLog; const bool dictIsDefined = (isFixedDict || method.Get_DicSize(dict)); - const int level = method.GetLevel(); + const unsigned level = method.GetLevel(); - if (method.MethodName.IsEmpty()) - method.MethodName = "LZMA"; + AString &methodName = method.MethodName; + const AString original_MethodName = methodName; + if (methodName.IsEmpty()) + methodName = "LZMA"; if (benchCallback) { @@ -3949,7 +4094,7 @@ HRESULT Bench( return MethodBench( EXTERNAL_CODECS_LOC_VARS complexInCommands, - #ifndef _7ZIP_ST + #ifndef Z7_ST true, numThreadsSpecified, &affinityMode, #endif @@ -3958,13 +4103,28 @@ HRESULT Bench( kOldLzmaDictBits, printCallback, benchCallback, &benchProps); } - AString methodName (method.MethodName); if (methodName.IsEqualTo_Ascii_NoCase("CRC")) methodName = "crc32"; - method.MethodName = methodName; + CMethodId hashID; - - if (FindHashMethod(EXTERNAL_CODECS_LOC_VARS methodName, hashID)) + const bool isHashMethod = FindHashMethod(EXTERNAL_CODECS_LOC_VARS methodName, hashID); + int codecIndex = -1; + bool isFilter = false; + if (!isHashMethod) + { + UInt32 numStreams; + codecIndex = FindMethod_Index(EXTERNAL_CODECS_LOC_VARS original_MethodName, + true, // encode + hashID, numStreams, isFilter); + // we can allow non filter for BW tests + if (!isFilter) codecIndex = -1; + } + + CBenchCallbackToPrint callback; + callback.Init(); + callback._file = printCallback; + + if (isHashMethod || codecIndex != -1) { if (!printCallback) return S_FALSE; @@ -3981,17 +4141,27 @@ HRESULT Bench( dict64 = fileDataBuffer.Size(); } - // methhodName.RemoveChar(L'-'); - UInt32 complexity = 10000; + for (;;) + { + const int index = method.FindProp(NCoderPropID::kDictionarySize); + if (index < 0) + break; + method.Props.Delete((unsigned)index); + } + + // methodName.RemoveChar(L'-'); + Int32 complexity = 16 * k_Hash_Complex_Mult; // for unknown hash method const UInt32 *checkSum = NULL; + int benchIndex = -1; + + if (isHashMethod) { - unsigned i; - for (i = 0; i < ARRAY_SIZE(g_Hash); i++) + for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Hash); i++) { const CBenchHash &h = g_Hash[i]; AString benchMethod (h.Name); AString benchProps; - int propPos = benchMethod.Find(':'); + const int propPos = benchMethod.Find(':'); if (propPos >= 0) { benchProps = benchMethod.Ptr((unsigned)(propPos + 1)); @@ -4000,45 +4170,80 @@ HRESULT Bench( if (AreSameMethodNames(benchMethod, methodName)) { - bool isMainMathed = method.PropsString.IsEmpty(); - if (isMainMathed) - isMainMathed = !checkSum - || (benchMethod.IsEqualTo_Ascii_NoCase("crc32") && benchProps.IsEqualTo_Ascii_NoCase("8")); const bool sameProps = method.PropsString.IsEqualTo_Ascii_NoCase(benchProps); - if (sameProps || isMainMathed) + /* + bool isMainMethod = method.PropsString.IsEmpty(); + if (isMainMethod) + isMainMethod = !checkSum + || (benchMethod.IsEqualTo_Ascii_NoCase("crc32") && benchProps.IsEqualTo_Ascii_NoCase("8")); + if (sameProps || isMainMethod) + */ { - complexity = h.Complex; + complexity = (Int32)h.Complex; checkSum = &h.CheckSum; if (sameProps) break; + /* + if property. is not specified, we use the complexity + for latest fastest method (crc32:64) + */ } } } - if (!checkSum) - return E_NOTIMPL; + // if (!checkSum) return E_NOTIMPL; + } + else + { + for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++) + { + const CBenchMethod &bench = g_Bench[i]; + AString benchMethod (bench.Name); + AString benchProps; + const int propPos = benchMethod.Find(':'); + if (propPos >= 0) + { + benchProps = benchMethod.Ptr((unsigned)(propPos + 1)); + benchMethod.DeleteFrom((unsigned)propPos); + } + + if (AreSameMethodNames(benchMethod, methodName)) + { + const bool sameProps = method.PropsString.IsEqualTo_Ascii_NoCase(benchProps); + // bool isMainMethod = method.PropsString.IsEmpty(); + // if (sameProps || isMainMethod) + { + benchIndex = (int)i; + if (sameProps) + break; + } + } + } + // if (benchIndex < 0) return E_NOTIMPL; } { - UInt64 usage = 1 << 20; + /* we count usage only for crc and filter. non-filters are not supported */ + UInt64 usage = (1 << 20); UInt64 bufSize = dict64; + UInt32 numBlocks = isHashMethod ? 1 : 3; if (use_fileData) { usage += fileDataBuffer.Size(); if (bufSize > fileDataBuffer.Size()) bufSize = fileDataBuffer.Size(); - #ifndef _7ZIP_ST - if (numThreadsSpecified != 1) - usage += bufSize * numThreadsSpecified * (k_Crc_CreateLocalBuf_For_File ? 1 : 0); - #endif + if (isHashMethod) + { + numBlocks = 0; + #ifndef Z7_ST + if (numThreadsSpecified != 1) + numBlocks = (k_Crc_CreateLocalBuf_For_File ? 1 : 0); + #endif + } } - else - usage += numThreadsSpecified * bufSize; + usage += numThreadsSpecified * bufSize * numBlocks; Print_Usage_and_Threads(f, usage, numThreadsSpecified); } - - f.NewLine(); - - const unsigned kFieldSize_CrcSpeed = 7; + CUIntVector numThreadsVector; { unsigned nt = numThreads_Start; @@ -4047,136 +4252,225 @@ HRESULT Bench( if (nt > numThreadsSpecified) break; numThreadsVector.Add(nt); - unsigned next = nt * 2; - UInt32 ntHalf= numThreadsSpecified / 2; + const unsigned next = nt * 2; + const UInt32 ntHalf= numThreadsSpecified / 2; if (ntHalf > nt && ntHalf < next) numThreadsVector.Add(ntHalf); if (numThreadsSpecified > nt && numThreadsSpecified < next) numThreadsVector.Add(numThreadsSpecified); nt = next; } + } + + unsigned numColumns = isHashMethod ? 1 : 2; + CTempValues speedTotals; + CTempValues usageTotals; + { + const unsigned numItems = numThreadsVector.Size() * numColumns; + speedTotals.Alloc(numItems); + usageTotals.Alloc(numItems); + for (unsigned i = 0; i < numItems; i++) { - f.NewLine(); - f.Print("THRD"); - FOR_VECTOR (ti, numThreadsVector) - { - PrintNumber(f, numThreadsVector[ti], 1 + kFieldSize_Usage + kFieldSize_CrcSpeed); - } + speedTotals.Values[i] = 0; + usageTotals.Values[i] = 0; } + } + + f.NewLine(); + for (unsigned line = 0; line < 3; line++) + { + f.NewLine(); + f.Print(line == 0 ? "THRD" : line == 1 ? " " : "Size"); + FOR_VECTOR (ti, numThreadsVector) { - f.NewLine(); - f.Print(" "); - FOR_VECTOR (ti, numThreadsVector) + if (ti != 0) + Print_Delimiter(f); + if (line == 0) { - PrintRight(f, "Usage", kFieldSize_Usage + 1); - PrintRight(f, "BW", kFieldSize_CrcSpeed + 1); + PrintSpaces(f, (kFieldSize_CrcSpeed + kFieldSize_Usage + 2) * (numColumns - 1)); + PrintNumber(f, numThreadsVector[ti], 1 + kFieldSize_Usage + kFieldSize_CrcSpeed); } - } - { - f.NewLine(); - f.Print("Size"); - FOR_VECTOR (ti, numThreadsVector) + else { - PrintRight(f, "%", kFieldSize_Usage + 1); - PrintRight(f, "MB/s", kFieldSize_CrcSpeed + 1); + for (unsigned c = 0; c < numColumns; c++) + { + PrintRight(f, line == 1 ? "Usage" : "%", kFieldSize_Usage + 1); + PrintRight(f, line == 1 ? "BW" : "MB/s", kFieldSize_CrcSpeed + 1); + } } } } - - f.NewLine(); f.NewLine(); - CTempValues speedTotals(numThreadsVector.Size()); - CTempValues usageTotals(numThreadsVector.Size()); - { - FOR_VECTOR (ti, numThreadsVector) - { - speedTotals.Values[ti] = 0; - usageTotals.Values[ti] = 0; - } - } - UInt64 numSteps = 0; - for (UInt32 i = 0; i < numIterations; i++) + // for (UInt32 iter = 0; iter < numIterations; iter++) + // { + unsigned pow = 10; // kNumHashDictBits + if (startDicLog_Defined) + pow = startDicLog; + + // #define NUM_SUB_BITS 2 + // pow <<= NUM_SUB_BITS; + for (;; pow++) { - unsigned pow = 10; // kNumHashDictBits - if (startDicLog_Defined) - pow = startDicLog; - for (;; pow++) - { - const UInt64 bufSize = (UInt64)1 << pow; - char s[16]; - ConvertUInt32ToString(pow, s); - unsigned pos = MyStringLen(s); - s[pos++] = ':'; - s[pos++] = ' '; - s[pos] = 0; - PrintRight(f, s, 4); - - size_t dataSize = fileDataBuffer.Size(); - if (dataSize > bufSize || !use_fileData) - dataSize = (size_t)bufSize; + const UInt64 bufSize = (UInt64)1 << pow; + // UInt64 bufSize = (UInt64)1 << (pow >> NUM_SUB_BITS); + // bufSize += ((UInt64)pow & ((1 << NUM_SUB_BITS) - 1)) << ((pow >> NUM_SUB_BITS) - NUM_SUB_BITS); + size_t dataSize = fileDataBuffer.Size(); + if (dataSize > bufSize || !use_fileData) + dataSize = (size_t)bufSize; + + for (UInt32 iter = 0; iter < numIterations; iter++) + { + Print_Pow(f, pow); + // PrintNumber(f, bufSize >> 10, 4); + FOR_VECTOR (ti, numThreadsVector) { - RINOK(f.CheckBreak()); - const UInt32 t = numThreadsVector[ti]; - UInt64 speed = 0; - UInt64 usage = 0; - - HRESULT res = CrcBench(EXTERNAL_CODECS_LOC_VARS complexInCommands, - t, + RINOK(f.CheckBreak()) + const UInt32 numThreads = numThreadsVector[ti]; + if (isHashMethod) + { + UInt64 speed = 0; + UInt64 usage = 0; + const HRESULT res = CrcBench(EXTERNAL_CODECS_LOC_VARS complexInCommands, + numThreads, dataSize, (const Byte *)fileDataBuffer, speed, usage, - complexity, + (UInt32)complexity, 1, // benchWeight, (pow == kNumHashDictBits && !use_fileData) ? checkSum : NULL, method, &f, - #ifndef _7ZIP_ST + #ifndef Z7_ST &affinityMode, #endif false, // showRating NULL, false, 0); - - RINOK(res); - - PrintUsage(f, usage, kFieldSize_Usage); - PrintNumber(f, speed / 1000000, kFieldSize_CrcSpeed); - speedTotals.Values[ti] += speed; - usageTotals.Values[ti] += usage; + RINOK(res) + + if (ti != 0) + Print_Delimiter(f); + + Bench_BW_Print_Usage_Speed(f, usage, speed); + speedTotals.Values[ti] += speed; + usageTotals.Values[ti] += usage; + } + else + { + { + unsigned keySize = 32; + if (IsString1PrefixedByString2(methodName, "AES128")) keySize = 16; + else if (IsString1PrefixedByString2(methodName, "AES192")) keySize = 24; + callback.BenchProps.KeySize = keySize; + } + + COneMethodInfo method2 = method; + unsigned bench_DictBits; + + if (benchIndex >= 0) + { + const CBenchMethod &bench = g_Bench[benchIndex]; + callback.BenchProps.EncComplex = bench.EncComplex; + callback.BenchProps.DecComplexUnc = bench.DecComplexUnc; + callback.BenchProps.DecComplexCompr = bench.DecComplexCompr; + bench_DictBits = bench.DictBits; + // bench_DictBits = kOldLzmaDictBits; = 32 default : for debug + } + else + { + bench_DictBits = kOldLzmaDictBits; // = 32 default + if (isFilter) + { + const unsigned k_UnknownCoderComplexity = 4; + callback.BenchProps.EncComplex = k_UnknownCoderComplexity; + callback.BenchProps.DecComplexUnc = k_UnknownCoderComplexity; + } + else + { + callback.BenchProps.EncComplex = 1 << 10; + callback.BenchProps.DecComplexUnc = 1 << 6; + } + callback.BenchProps.DecComplexCompr = 0; + } + callback.NeedPrint = false; + + if (StringsAreEqualNoCase_Ascii(method2.MethodName, "LZMA")) + { + const NCOM::CPropVariant propVariant = (UInt32)pow; + RINOK(method2.ParseMethodFromPROPVARIANT((UString)"d", propVariant)) + } + + const HRESULT res = MethodBench( + EXTERNAL_CODECS_LOC_VARS + complexInCommands, + #ifndef Z7_ST + false, // oldLzmaBenchMode + numThreadsVector[ti], + &affinityMode, + #endif + method2, + dataSize, (const Byte *)fileDataBuffer, + bench_DictBits, + printCallback, + &callback, + &callback.BenchProps); + RINOK(res) + + if (ti != 0) + Print_Delimiter(f); + + for (unsigned i = 0; i < 2; i++) + { + const CBenchInfo &bi = callback.BenchInfo_Results[i]; + const UInt64 usage = bi.GetUsage(); + const UInt64 speed = bi.GetUnpackSizeSpeed(); + usageTotals.Values[ti * 2 + i] += usage; + speedTotals.Values[ti * 2 + i] += speed; + Bench_BW_Print_Usage_Speed(f, usage, speed); + } + } } f.NewLine(); numSteps++; - if (dataSize >= dict64) - break; } + if (dataSize >= dict64) + break; } + if (numSteps != 0) { - f.NewLine(); f.Print("Avg:"); for (unsigned ti = 0; ti < numThreadsVector.Size(); ti++) { - PrintUsage(f, usageTotals.Values[ti] / numSteps, kFieldSize_Usage); - PrintNumber(f, speedTotals.Values[ti] / numSteps / 1000000, kFieldSize_CrcSpeed); + if (ti != 0) + Print_Delimiter(f); + for (unsigned i = 0; i < numColumns; i++) + Bench_BW_Print_Usage_Speed(f, + usageTotals.Values[ti * numColumns + i] / numSteps, + speedTotals.Values[ti * numColumns + i] / numSteps); } f.NewLine(); } + return S_OK; } bool use2Columns = false; - bool totalBenchMode = (method.MethodName.IsEqualTo_Ascii_NoCase("*")); + bool totalBenchMode = false; bool onlyHashBench = false; - if (method.MethodName.IsEqualTo_Ascii_NoCase("hash")) + if (methodName.IsEqualTo_Ascii_NoCase("hash")) { onlyHashBench = true; + methodName = "*"; totalBenchMode = true; } + else if (methodName.Find('*') >= 0) + totalBenchMode = true; // ---------- Threads loop ---------- for (unsigned threadsPassIndex = 0; threadsPassIndex < 3; threadsPassIndex++) @@ -4207,10 +4501,6 @@ HRESULT Bench( } } - CBenchCallbackToPrint callback; - callback.Init(); - callback._file = printCallback; - IBenchPrintCallback &f = *printCallback; if (threadsPassIndex > 0) @@ -4230,7 +4520,7 @@ HRESULT Bench( if (ramSize_Defined) for (; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--) - if (GetBenchMemoryUsage(numThreads, level, ((UInt64)1 << dicSizeLog), totalBenchMode) + (8 << 20) <= ramSize) + if (GetBenchMemoryUsage(numThreads, (int)level, ((UInt64)1 << dicSizeLog), totalBenchMode) + (8 << 20) <= ramSize) break; dict = (UInt64)1 << dicSizeLog; @@ -4246,7 +4536,7 @@ HRESULT Bench( Print_Usage_and_Threads(f, onlyHashBench ? GetBenchMemoryUsage_Hash(numThreads, dict) : - GetBenchMemoryUsage(numThreads, level, dict, totalBenchMode), + GetBenchMemoryUsage(numThreads, (int)level, dict, totalBenchMode), numThreads); f.NewLine(); @@ -4355,12 +4645,12 @@ HRESULT Bench( fb.showFreq = (freqTest == kNumCpuTests - 1 || specifiedFreq != 0); fb.specifiedFreq = specifiedFreq; - HRESULT res = fb.FreqBench(printCallback - #ifndef _7ZIP_ST + const HRESULT res = fb.FreqBench(printCallback + #ifndef Z7_ST , &affinityMode #endif ); - RINOK(res); + RINOK(res) cpuFreq = fb.CpuFreqRes; callback.NewLine(); @@ -4390,9 +4680,9 @@ HRESULT Bench( dataSize = (size_t)dict; } - HRESULT res = TotalBench(EXTERNAL_CODECS_LOC_VARS - complexInCommands, - #ifndef _7ZIP_ST + const HRESULT res = TotalBench(EXTERNAL_CODECS_LOC_VARS + method, complexInCommands, + #ifndef Z7_ST numThreads, &affinityMode, #endif @@ -4400,7 +4690,7 @@ HRESULT Bench( dataSize, (const Byte *)fileDataBuffer, printCallback, &callback); - RINOK(res); + RINOK(res) } { @@ -4418,14 +4708,16 @@ HRESULT Bench( dataSize = (size_t)dict; } - HRESULT res = TotalBench_Hash(EXTERNAL_CODECS_LOC_VARS complexInCommands, numThreads, + const HRESULT res = TotalBench_Hash(EXTERNAL_CODECS_LOC_VARS + method, complexInCommands, + numThreads, dataSize, (const Byte *)fileDataBuffer, printCallback, &callback, - #ifndef _7ZIP_ST + #ifndef Z7_ST &affinityMode, #endif &callback.EncodeRes, true, cpuFreq); - RINOK(res); + RINOK(res) } callback.NewLine(); @@ -4439,12 +4731,12 @@ HRESULT Bench( fb.showFreq = (specifiedFreq != 0); fb.specifiedFreq = specifiedFreq; - HRESULT res = fb.FreqBench(printCallback - #ifndef _7ZIP_ST + const HRESULT res = fb.FreqBench(printCallback + #ifndef Z7_ST , &affinityMode #endif ); - RINOK(res); + RINOK(res) callback.NewLine(); } } @@ -4455,12 +4747,12 @@ HRESULT Bench( if (!methodName.IsEqualTo_Ascii_NoCase("LZMA")) { unsigned i; - for (i = 0; i < ARRAY_SIZE(g_Bench); i++) + for (i = 0; i < Z7_ARRAY_SIZE(g_Bench); i++) { const CBenchMethod &h = g_Bench[i]; AString benchMethod (h.Name); AString benchProps; - int propPos = benchMethod.Find(':'); + const int propPos = benchMethod.Find(':'); if (propPos >= 0) { benchProps = benchMethod.Ptr((unsigned)(propPos + 1)); @@ -4475,14 +4767,16 @@ HRESULT Bench( { callback.BenchProps.EncComplex = h.EncComplex; callback.BenchProps.DecComplexCompr = h.DecComplexCompr; - callback.BenchProps.DecComplexUnc = h.DecComplexUnc;; + callback.BenchProps.DecComplexUnc = h.DecComplexUnc; needSetComplexity = false; break; } } } - if (i == ARRAY_SIZE(g_Bench)) + /* + if (i == Z7_ARRAY_SIZE(g_Bench)) return E_NOTIMPL; + */ } if (needSetComplexity) callback.BenchProps.SetLzmaCompexity(); @@ -4499,12 +4793,7 @@ HRESULT Bench( pow--; for (; GetDictSizeFromLog(pow) <= dict; pow++) { - char s[16]; - ConvertUInt32ToString(pow, s); - unsigned pos = MyStringLen(s); - s[pos++] = ':'; - s[pos] = 0; - PrintLeft(f, s, kFieldSize_SmallName); + Print_Pow(f, pow); callback.DictSize = (UInt64)1 << pow; COneMethodInfo method2 = method; @@ -4515,7 +4804,7 @@ HRESULT Bench( // method2 can have two different dictionary size properties. // And last property is main. NCOM::CPropVariant propVariant = (UInt32)pow; - RINOK(method2.ParseMethodFromPROPVARIANT((UString)"d", propVariant)); + RINOK(method2.ParseMethodFromPROPVARIANT((UString)"d", propVariant)) } size_t uncompressedDataSize; @@ -4532,10 +4821,10 @@ HRESULT Bench( uncompressedDataSize += kAdditionalSize; } - HRESULT res = MethodBench( + const HRESULT res = MethodBench( EXTERNAL_CODECS_LOC_VARS complexInCommands, - #ifndef _7ZIP_ST + #ifndef Z7_ST true, numThreads, &affinityMode, #endif @@ -4543,7 +4832,7 @@ HRESULT Bench( uncompressedDataSize, (const Byte *)fileDataBuffer, kOldLzmaDictBits, printCallback, &callback, &callback.BenchProps); f.NewLine(); - RINOK(res); + RINOK(res) if (!multiDict) break; } |