mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 14:24:09 -06:00
4.45 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
d9666cf046
commit
a145bfc7cf
@@ -0,0 +1,584 @@
|
||||
// BenchmarkDialog.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/IntToString.h"
|
||||
#include "Common/StringToInt.h"
|
||||
#include "Common/Exception.h"
|
||||
#include "Windows/Thread.h"
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/System.h"
|
||||
#include "../../../../FileManager/HelpUtils.h"
|
||||
#include "resource.h"
|
||||
#include "BenchmarkDialog.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
// const int kNumBenchDictionaryBitsStart = 21;
|
||||
|
||||
static LPCWSTR kHelpTopic = L"fm/benchmark.htm";
|
||||
|
||||
static const UINT_PTR kTimerID = 4;
|
||||
static const UINT kTimerElapse = 1000;
|
||||
|
||||
#ifdef LANG
|
||||
#include "../../../../FileManager/LangUtils.h"
|
||||
#endif
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
#ifdef LANG
|
||||
static CIDLangPair kIDLangPairs[] =
|
||||
{
|
||||
{ IDC_BENCHMARK_DICTIONARY, 0x02000D0C },
|
||||
{ IDC_BENCHMARK_MEMORY, 0x03080001 },
|
||||
{ IDC_BENCHMARK_NUM_THREADS, 0x02000D12 },
|
||||
{ IDC_BENCHMARK_SPEED_LABEL, 0x03080004 },
|
||||
{ IDC_BENCHMARK_RATING_LABEL, 0x03080005 },
|
||||
{ IDC_BENCHMARK_COMPRESSING, 0x03080002 },
|
||||
{ IDC_BENCHMARK_DECOMPRESSING, 0x03080003 },
|
||||
{ IDC_BENCHMARK_CURRENT, 0x03080007 },
|
||||
{ IDC_BENCHMARK_RESULTING, 0x03080008 },
|
||||
{ IDC_BENCHMARK_CURRENT2, 0x03080007 },
|
||||
{ IDC_BENCHMARK_RESULTING2, 0x03080008 },
|
||||
{ IDC_BENCHMARK_TOTAL_RATING, 0x03080006 },
|
||||
{ IDC_BENCHMARK_ELAPSED, 0x02000C01 },
|
||||
{ IDC_BENCHMARK_SIZE, 0x02000C03 },
|
||||
{ IDC_BENCHMARK_PASSES, 0x03080009 },
|
||||
// { IDC_BENCHMARK_ERRORS, 0x0308000A },
|
||||
{ IDC_BENCHMARK_USAGE_LABEL, 0x0308000B },
|
||||
{ IDC_BENCHMARK_RPU_LABEL, 0x0308000C },
|
||||
{ IDC_BENCHMARK_COMBO_NUM_THREADS, 0x02000D12},
|
||||
|
||||
{ IDC_BUTTON_STOP, 0x02000714 },
|
||||
{ IDC_BUTTON_RESTART, 0x02000715 },
|
||||
{ IDHELP, 0x02000720 },
|
||||
{ IDCANCEL, 0x02000710 }
|
||||
};
|
||||
#endif
|
||||
|
||||
static void MyMessageBoxError(HWND hwnd, LPCWSTR message)
|
||||
{
|
||||
MessageBoxW(hwnd, message, L"7-Zip", MB_ICONERROR);
|
||||
}
|
||||
|
||||
const LPCTSTR kProcessingString = TEXT("...");
|
||||
const LPCTSTR kMB = TEXT(" MB");
|
||||
const LPCTSTR kMIPS = TEXT(" MIPS");
|
||||
const LPCTSTR kKBs = TEXT(" KB/s");
|
||||
|
||||
static const int kMinDicLogSize = 21;
|
||||
static const UInt32 kMinDicSize = (1 << kMinDicLogSize);
|
||||
static const UInt32 kMaxDicSize =
|
||||
#ifdef _WIN64
|
||||
(1 << 30);
|
||||
#else
|
||||
(1 << 27);
|
||||
#endif
|
||||
|
||||
static const int kDefaultDictionary = 22;
|
||||
|
||||
bool CBenchmarkDialog::OnInit()
|
||||
{
|
||||
#ifdef LANG
|
||||
LangSetWindowText(HWND(*this), 0x03080000);
|
||||
LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));
|
||||
#endif
|
||||
|
||||
_syncInfo.Init();
|
||||
|
||||
m_Dictionary.Attach(GetItem(IDC_BENCHMARK_COMBO_DICTIONARY));
|
||||
int cur = 0;
|
||||
// _syncInfo.DictionarySize = (1 << kNumBenchDictionaryBitsStart);
|
||||
|
||||
UInt32 numCPUs = NSystem::GetNumberOfProcessors();
|
||||
if (numCPUs < 1)
|
||||
numCPUs = 1;
|
||||
numCPUs = MyMin(numCPUs, (UInt32)(1 << 8));
|
||||
cur = 0;
|
||||
bool setDefaultThreads = (_syncInfo.NumThreads == (UInt32)(-1));
|
||||
if (setDefaultThreads)
|
||||
{
|
||||
_syncInfo.NumThreads = numCPUs;
|
||||
if (_syncInfo.NumThreads > 1)
|
||||
_syncInfo.NumThreads &= ~1;
|
||||
}
|
||||
|
||||
UInt64 ramSize = NSystem::GetRamSize();
|
||||
bool setDefaultDictionary = (_syncInfo.DictionarySize == (UInt32)(-1));
|
||||
if (setDefaultDictionary)
|
||||
{
|
||||
int dicSizeLog;
|
||||
for (dicSizeLog = 25; dicSizeLog >= kBenchMinDicLogSize; dicSizeLog--)
|
||||
if (GetBenchMemoryUsage(_syncInfo.NumThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)
|
||||
break;
|
||||
_syncInfo.DictionarySize = (1 << dicSizeLog);
|
||||
}
|
||||
if (_syncInfo.DictionarySize < kMinDicSize)
|
||||
_syncInfo.DictionarySize = kMinDicSize;
|
||||
if (_syncInfo.DictionarySize > kMaxDicSize)
|
||||
_syncInfo.DictionarySize = kMaxDicSize;
|
||||
|
||||
for (int i = kMinDicLogSize; i <= 30; i++)
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
UInt32 dictionary = (1 << i) + (j << (i - 1));
|
||||
if (dictionary > kMaxDicSize)
|
||||
continue;
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString((dictionary >> 20), s);
|
||||
lstrcat(s, kMB);
|
||||
int index = (int)m_Dictionary.AddString(s);
|
||||
m_Dictionary.SetItemData(index, dictionary);
|
||||
if (dictionary <= _syncInfo.DictionarySize)
|
||||
cur = index;
|
||||
}
|
||||
m_Dictionary.SetCurSel(cur);
|
||||
|
||||
m_NumThreads.Attach(GetItem(IDC_BENCHMARK_COMBO_NUM_THREADS));
|
||||
for (UInt32 num = 1; ;)
|
||||
{
|
||||
if (num > numCPUs * 2)
|
||||
break;
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString(num, s);
|
||||
int index = (int)m_NumThreads.AddString(s);
|
||||
m_NumThreads.SetItemData(index, num);
|
||||
if (num <= numCPUs && setDefaultThreads)
|
||||
{
|
||||
_syncInfo.NumThreads = num;
|
||||
cur = index;
|
||||
}
|
||||
if (num > 1)
|
||||
num++;
|
||||
num++;
|
||||
}
|
||||
m_NumThreads.SetCurSel(cur);
|
||||
|
||||
OnChangeSettings();
|
||||
|
||||
_syncInfo._startEvent.Set();
|
||||
_timer = SetTimer(kTimerID, kTimerElapse);
|
||||
return CModalDialog::OnInit();
|
||||
}
|
||||
|
||||
UInt32 CBenchmarkDialog::GetNumberOfThreads()
|
||||
{
|
||||
return (UInt32)m_NumThreads.GetItemData(m_NumThreads.GetCurSel());
|
||||
}
|
||||
|
||||
UInt32 CBenchmarkDialog::OnChangeDictionary()
|
||||
{
|
||||
UInt32 dictionary = (UInt32)m_Dictionary.GetItemData(m_Dictionary.GetCurSel());
|
||||
UInt64 memUsage = GetBenchMemoryUsage(GetNumberOfThreads(), dictionary);
|
||||
memUsage = (memUsage + (1 << 20) - 1) >> 20;
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString(memUsage, s);
|
||||
lstrcat(s, kMB);
|
||||
SetItemText(IDC_BENCHMARK_MEMORY_VALUE, s);
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
static const UInt32 g_IDs[] =
|
||||
{
|
||||
IDC_BENCHMARK_COMPRESSING_USAGE,
|
||||
IDC_BENCHMARK_COMPRESSING_USAGE2,
|
||||
IDC_BENCHMARK_COMPRESSING_SPEED,
|
||||
IDC_BENCHMARK_COMPRESSING_SPEED2,
|
||||
IDC_BENCHMARK_COMPRESSING_RATING,
|
||||
IDC_BENCHMARK_COMPRESSING_RATING2,
|
||||
IDC_BENCHMARK_COMPRESSING_RPU,
|
||||
IDC_BENCHMARK_COMPRESSING_RPU2,
|
||||
|
||||
IDC_BENCHMARK_DECOMPRESSING_SPEED,
|
||||
IDC_BENCHMARK_DECOMPRESSING_SPEED2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RATING,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RATING2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_USAGE,
|
||||
IDC_BENCHMARK_DECOMPRESSING_USAGE2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RPU,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RPU2,
|
||||
|
||||
IDC_BENCHMARK_TOTAL_USAGE_VALUE,
|
||||
IDC_BENCHMARK_TOTAL_RATING_VALUE,
|
||||
IDC_BENCHMARK_TOTAL_RPU_VALUE
|
||||
};
|
||||
|
||||
void CBenchmarkDialog::OnChangeSettings()
|
||||
{
|
||||
EnableItem(IDC_BUTTON_STOP, true);
|
||||
UInt32 dictionary = OnChangeDictionary();
|
||||
TCHAR s[40] = { TEXT('/'), TEXT(' '), 0 };
|
||||
ConvertUInt64ToString(NSystem::GetNumberOfProcessors(), s + 2);
|
||||
SetItemText(IDC_BENCHMARK_HARDWARE_THREADS, s);
|
||||
for (int i = 0; i < sizeof(g_IDs) / sizeof(g_IDs[0]); i++)
|
||||
SetItemText(g_IDs[i], kProcessingString);
|
||||
_startTime = GetTickCount();
|
||||
PrintTime();
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_syncInfo.CS);
|
||||
_syncInfo.Init();
|
||||
_syncInfo.DictionarySize = dictionary;
|
||||
_syncInfo.Changed = true;
|
||||
_syncInfo.NumThreads = GetNumberOfThreads();
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::OnRestartButton()
|
||||
{
|
||||
OnChangeSettings();
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::OnStopButton()
|
||||
{
|
||||
EnableItem(IDC_BUTTON_STOP, false);
|
||||
_syncInfo.Pause();
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::OnHelp()
|
||||
{
|
||||
ShowHelpWindow(NULL, kHelpTopic);
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::OnCancel()
|
||||
{
|
||||
_syncInfo.Stop();
|
||||
KillTimer(_timer);
|
||||
CModalDialog::OnCancel();
|
||||
}
|
||||
|
||||
static void GetTimeString(UInt64 timeValue, TCHAR *s)
|
||||
{
|
||||
wsprintf(s, TEXT("%02d:%02d:%02d"),
|
||||
UInt32(timeValue / 3600),
|
||||
UInt32((timeValue / 60) % 60),
|
||||
UInt32(timeValue % 60));
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::PrintTime()
|
||||
{
|
||||
UInt32 curTime = ::GetTickCount();
|
||||
UInt32 elapsedTime = (curTime - _startTime);
|
||||
UInt32 elapsedSec = elapsedTime / 1000;
|
||||
if (elapsedSec != 0 && _syncInfo.WasPaused())
|
||||
return;
|
||||
TCHAR s[40];
|
||||
GetTimeString(elapsedSec, s);
|
||||
SetItemText(IDC_BENCHMARK_ELAPSED_VALUE, s);
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::PrintRating(UInt64 rating, UINT controlID)
|
||||
{
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString(rating / 1000000, s);
|
||||
lstrcat(s, kMIPS);
|
||||
SetItemText(controlID, s);
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::PrintUsage(UInt64 usage, UINT controlID)
|
||||
{
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString((usage + 5000) / 10000, s);
|
||||
lstrcat(s, TEXT("%"));
|
||||
SetItemText(controlID, s);
|
||||
}
|
||||
|
||||
void CBenchmarkDialog::PrintResults(
|
||||
UInt32 dictionarySize,
|
||||
const CBenchInfo2 &info,
|
||||
UINT usageID, UINT speedID, UINT rpuID, UINT ratingID,
|
||||
bool decompressMode)
|
||||
{
|
||||
if (info.GlobalTime == 0)
|
||||
return;
|
||||
|
||||
UInt64 size = info.UnpackSize;
|
||||
TCHAR s[40];
|
||||
{
|
||||
UInt64 speed = size * info.GlobalFreq / info.GlobalTime;
|
||||
ConvertUInt64ToString(speed / 1024, s);
|
||||
lstrcat(s, kKBs);
|
||||
SetItemText(speedID, s);
|
||||
}
|
||||
UInt64 rating;
|
||||
if (decompressMode)
|
||||
rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, size, info.PackSize, 1);
|
||||
else
|
||||
rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, size * info.NumIterations);
|
||||
|
||||
PrintRating(rating, ratingID);
|
||||
PrintRating(GetRatingPerUsage(info, rating), rpuID);
|
||||
PrintUsage(GetUsage(info), usageID);
|
||||
}
|
||||
|
||||
bool CBenchmarkDialog::OnTimer(WPARAM /* timerID */, LPARAM /* callback */)
|
||||
{
|
||||
PrintTime();
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(_syncInfo.CS);
|
||||
|
||||
TCHAR s[40];
|
||||
ConvertUInt64ToString((_syncInfo.ProcessedSize >> 20), s);
|
||||
lstrcat(s, kMB);
|
||||
SetItemText(IDC_BENCHMARK_SIZE_VALUE, s);
|
||||
|
||||
ConvertUInt64ToString(_syncInfo.NumPasses, s);
|
||||
SetItemText(IDC_BENCHMARK_PASSES_VALUE, s);
|
||||
|
||||
/*
|
||||
ConvertUInt64ToString(_syncInfo.NumErrors, s);
|
||||
SetItemText(IDC_BENCHMARK_ERRORS_VALUE, s);
|
||||
*/
|
||||
|
||||
{
|
||||
UInt32 dicSizeTemp = (UInt32)MyMax(_syncInfo.ProcessedSize, UInt64(1) << 20);
|
||||
dicSizeTemp = MyMin(dicSizeTemp, _syncInfo.DictionarySize),
|
||||
PrintResults(dicSizeTemp,
|
||||
_syncInfo.CompressingInfoTemp,
|
||||
IDC_BENCHMARK_COMPRESSING_USAGE,
|
||||
IDC_BENCHMARK_COMPRESSING_SPEED,
|
||||
IDC_BENCHMARK_COMPRESSING_RPU,
|
||||
IDC_BENCHMARK_COMPRESSING_RATING);
|
||||
}
|
||||
|
||||
{
|
||||
PrintResults(
|
||||
_syncInfo.DictionarySize,
|
||||
_syncInfo.CompressingInfo,
|
||||
IDC_BENCHMARK_COMPRESSING_USAGE2,
|
||||
IDC_BENCHMARK_COMPRESSING_SPEED2,
|
||||
IDC_BENCHMARK_COMPRESSING_RPU2,
|
||||
IDC_BENCHMARK_COMPRESSING_RATING2);
|
||||
}
|
||||
|
||||
{
|
||||
PrintResults(
|
||||
_syncInfo.DictionarySize,
|
||||
_syncInfo.DecompressingInfoTemp,
|
||||
IDC_BENCHMARK_DECOMPRESSING_USAGE,
|
||||
IDC_BENCHMARK_DECOMPRESSING_SPEED,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RPU,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RATING,
|
||||
true);
|
||||
}
|
||||
{
|
||||
PrintResults(
|
||||
_syncInfo.DictionarySize,
|
||||
_syncInfo.DecompressingInfo,
|
||||
IDC_BENCHMARK_DECOMPRESSING_USAGE2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_SPEED2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RPU2,
|
||||
IDC_BENCHMARK_DECOMPRESSING_RATING2,
|
||||
true);
|
||||
if (_syncInfo.DecompressingInfo.GlobalTime > 0 &&
|
||||
_syncInfo.CompressingInfo.GlobalTime > 0)
|
||||
{
|
||||
UInt64 comprRating = GetCompressRating(_syncInfo.DictionarySize,
|
||||
_syncInfo.CompressingInfo.GlobalTime, _syncInfo.CompressingInfo.GlobalFreq, _syncInfo.CompressingInfo.UnpackSize);
|
||||
UInt64 decomprRating = GetDecompressRating(_syncInfo.DecompressingInfo.GlobalTime,
|
||||
_syncInfo.DecompressingInfo.GlobalFreq, _syncInfo.DecompressingInfo.UnpackSize,
|
||||
_syncInfo.DecompressingInfo.PackSize, 1);
|
||||
PrintRating((comprRating + decomprRating) / 2, IDC_BENCHMARK_TOTAL_RATING_VALUE);
|
||||
PrintRating((
|
||||
GetRatingPerUsage(_syncInfo.CompressingInfo, comprRating) +
|
||||
GetRatingPerUsage(_syncInfo.DecompressingInfo, decomprRating)) / 2, IDC_BENCHMARK_TOTAL_RPU_VALUE);
|
||||
PrintUsage((GetUsage(_syncInfo.CompressingInfo) + GetUsage(_syncInfo.DecompressingInfo)) / 2, IDC_BENCHMARK_TOTAL_USAGE_VALUE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBenchmarkDialog::OnCommand(int code, int itemID, LPARAM lParam)
|
||||
{
|
||||
if (code == CBN_SELCHANGE &&
|
||||
(itemID == IDC_BENCHMARK_COMBO_DICTIONARY ||
|
||||
itemID == IDC_BENCHMARK_COMBO_NUM_THREADS))
|
||||
{
|
||||
OnChangeSettings();
|
||||
return true;
|
||||
}
|
||||
return CModalDialog::OnCommand(code, itemID, lParam);
|
||||
}
|
||||
|
||||
bool CBenchmarkDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
|
||||
{
|
||||
switch(buttonID)
|
||||
{
|
||||
case IDC_BUTTON_RESTART:
|
||||
OnRestartButton();
|
||||
return true;
|
||||
case IDC_BUTTON_STOP:
|
||||
OnStopButton();
|
||||
return true;
|
||||
}
|
||||
return CModalDialog::OnButtonClicked(buttonID, buttonHWND);
|
||||
}
|
||||
|
||||
struct CThreadBenchmark
|
||||
{
|
||||
CProgressSyncInfo *SyncInfo;
|
||||
UInt64 _startTime;
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs;
|
||||
#endif
|
||||
// UInt32 dictionarySize;
|
||||
// UInt32 numThreads;
|
||||
|
||||
HRESULT Process();
|
||||
HRESULT Result;
|
||||
static DWORD WINAPI MyThreadFunction(void *param)
|
||||
{
|
||||
((CThreadBenchmark *)param)->Result = ((CThreadBenchmark *)param)->Process();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CBenchCallback: public IBenchCallback
|
||||
{
|
||||
UInt32 dictionarySize;
|
||||
CProgressSyncInfo *SyncInfo;
|
||||
HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
|
||||
HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
|
||||
};
|
||||
|
||||
HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(SyncInfo->CS);
|
||||
if (SyncInfo->Changed || SyncInfo->Paused || SyncInfo->Stopped)
|
||||
return E_ABORT;
|
||||
SyncInfo->ProcessedSize = info.UnpackSize;
|
||||
if (final && SyncInfo->CompressingInfo.GlobalTime == 0)
|
||||
{
|
||||
(CBenchInfo&)SyncInfo->CompressingInfo = info;
|
||||
if (SyncInfo->CompressingInfo.GlobalTime == 0)
|
||||
SyncInfo->CompressingInfo.GlobalTime = 1;
|
||||
}
|
||||
else
|
||||
(CBenchInfo&)SyncInfo->CompressingInfoTemp = info;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(SyncInfo->CS);
|
||||
if (SyncInfo->Changed || SyncInfo->Paused || SyncInfo->Stopped)
|
||||
return E_ABORT;
|
||||
CBenchInfo info2 = info;
|
||||
if (info2.NumIterations == 0)
|
||||
info2.NumIterations = 1;
|
||||
|
||||
info2.GlobalTime /= info2.NumIterations;
|
||||
info2.UserTime /= info2.NumIterations;
|
||||
|
||||
if (final && SyncInfo->DecompressingInfo.GlobalTime == 0)
|
||||
{
|
||||
(CBenchInfo&)SyncInfo->DecompressingInfo = info2;
|
||||
if (SyncInfo->DecompressingInfo.GlobalTime == 0)
|
||||
SyncInfo->DecompressingInfo.GlobalTime = 1;
|
||||
}
|
||||
else
|
||||
(CBenchInfo&)SyncInfo->DecompressingInfoTemp = info2;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CThreadBenchmark::Process()
|
||||
{
|
||||
try
|
||||
{
|
||||
SyncInfo->WaitCreating();
|
||||
for (;;)
|
||||
{
|
||||
if (SyncInfo->WasStopped())
|
||||
return 0;
|
||||
if (SyncInfo->WasPaused())
|
||||
{
|
||||
Sleep(200);
|
||||
continue;
|
||||
}
|
||||
UInt32 dictionarySize;
|
||||
UInt32 numThreads;
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(SyncInfo->CS);
|
||||
if (SyncInfo->Stopped || SyncInfo->Paused)
|
||||
continue;
|
||||
if (SyncInfo->Changed)
|
||||
SyncInfo->Init();
|
||||
dictionarySize = SyncInfo->DictionarySize;
|
||||
numThreads = SyncInfo->NumThreads;
|
||||
}
|
||||
|
||||
CBenchCallback callback;
|
||||
callback.dictionarySize = dictionarySize;
|
||||
callback.SyncInfo = SyncInfo;
|
||||
HRESULT result;
|
||||
try
|
||||
{
|
||||
result = LzmaBench(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
codecs,
|
||||
#endif
|
||||
numThreads, dictionarySize, &callback);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
result = E_FAIL;
|
||||
}
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (result != E_ABORT)
|
||||
{
|
||||
// SyncInfo->NumErrors++;
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(SyncInfo->CS);
|
||||
SyncInfo->Pause();
|
||||
}
|
||||
CSysString message;
|
||||
if (result == S_FALSE)
|
||||
message = TEXT("Decoding error");
|
||||
else
|
||||
message = NError::MyFormatMessage(result);
|
||||
MessageBox(0, message, TEXT("7-Zip"), MB_ICONERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(SyncInfo->CS);
|
||||
SyncInfo->NumPasses++;
|
||||
}
|
||||
}
|
||||
// return S_OK;
|
||||
}
|
||||
catch(CSystemException &e)
|
||||
{
|
||||
MessageBox(0, NError::MyFormatMessage(e.ErrorCode), TEXT("7-Zip"), MB_ICONERROR);
|
||||
return E_FAIL;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
MyMessageBoxError(0, L"Some error");
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT Benchmark(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs,
|
||||
#endif
|
||||
UInt32 numThreads, UInt32 dictionarySize)
|
||||
{
|
||||
CThreadBenchmark benchmarker;
|
||||
#ifdef EXTERNAL_LZMA
|
||||
benchmarker.codecs = codecs;
|
||||
#endif
|
||||
|
||||
CBenchmarkDialog benchmarkDialog;
|
||||
benchmarkDialog._syncInfo.DictionarySize = dictionarySize;
|
||||
benchmarkDialog._syncInfo.NumThreads = numThreads;
|
||||
|
||||
benchmarker.SyncInfo = &benchmarkDialog._syncInfo;
|
||||
CThread thread;
|
||||
if (!thread.Create(CThreadBenchmark::MyThreadFunction, &benchmarker))
|
||||
return E_FAIL;
|
||||
benchmarkDialog.Create(0);
|
||||
thread.Wait();
|
||||
return S_OK;
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
// BenchmarkDialog.h
|
||||
|
||||
#ifndef __BENCHMARKDIALOG_H
|
||||
#define __BENCHMARKDIALOG_H
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#include "Windows/Control/Dialog.h"
|
||||
#include "Windows/Control/ComboBox.h"
|
||||
#include "Windows/Synchronization.h"
|
||||
#include "../../../../Compress/LZMA_Alone/LzmaBench.h"
|
||||
|
||||
#ifdef EXTERNAL_LZMA
|
||||
#include "../../../../UI/Common/LoadCodecs.h"
|
||||
#endif
|
||||
|
||||
struct CBenchInfo2 : public CBenchInfo
|
||||
{
|
||||
void Init() { GlobalTime = UserTime = 0; }
|
||||
};
|
||||
|
||||
class CProgressSyncInfo
|
||||
{
|
||||
public:
|
||||
bool Stopped;
|
||||
bool Paused;
|
||||
bool Changed;
|
||||
UInt32 DictionarySize;
|
||||
UInt32 NumThreads;
|
||||
UInt64 NumPasses;
|
||||
// UInt64 NumErrors;
|
||||
NWindows::NSynchronization::CManualResetEvent _startEvent;
|
||||
NWindows::NSynchronization::CCriticalSection CS;
|
||||
|
||||
CBenchInfo2 CompressingInfoTemp;
|
||||
CBenchInfo2 CompressingInfo;
|
||||
UInt64 ProcessedSize;
|
||||
|
||||
CBenchInfo2 DecompressingInfoTemp;
|
||||
CBenchInfo2 DecompressingInfo;
|
||||
|
||||
void Init()
|
||||
{
|
||||
Changed = false;
|
||||
Stopped = false;
|
||||
Paused = false;
|
||||
CompressingInfoTemp.Init();
|
||||
CompressingInfo.Init();
|
||||
ProcessedSize = 0;
|
||||
|
||||
DecompressingInfoTemp.Init();
|
||||
DecompressingInfo.Init();
|
||||
|
||||
NumPasses = 0;
|
||||
// NumErrors = 0;
|
||||
}
|
||||
void Stop()
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
Stopped = true;
|
||||
}
|
||||
bool WasStopped()
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
return Stopped;
|
||||
}
|
||||
void Pause()
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
Paused = true;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
Paused = false;
|
||||
}
|
||||
bool WasPaused()
|
||||
{
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
return Paused;
|
||||
}
|
||||
void WaitCreating() { _startEvent.Lock(); }
|
||||
};
|
||||
|
||||
class CBenchmarkDialog:
|
||||
public NWindows::NControl::CModalDialog
|
||||
{
|
||||
NWindows::NControl::CComboBox m_Dictionary;
|
||||
NWindows::NControl::CComboBox m_NumThreads;
|
||||
UINT_PTR _timer;
|
||||
UINT32 _startTime;
|
||||
|
||||
bool OnTimer(WPARAM timerID, LPARAM callback);
|
||||
virtual bool OnInit();
|
||||
void OnRestartButton();
|
||||
void OnStopButton();
|
||||
void OnHelp();
|
||||
virtual void OnCancel();
|
||||
bool OnButtonClicked(int buttonID, HWND buttonHWND);
|
||||
bool OnCommand(int code, int itemID, LPARAM lParam);
|
||||
|
||||
void PrintTime();
|
||||
void PrintRating(UInt64 rating, UINT controlID);
|
||||
void PrintUsage(UInt64 usage, UINT controlID);
|
||||
void PrintResults(
|
||||
UINT32 dictionarySize,
|
||||
const CBenchInfo2 &info, UINT usageID, UINT speedID, UINT rpuID, UINT ratingID,
|
||||
bool decompressMode = false);
|
||||
|
||||
UInt32 GetNumberOfThreads();
|
||||
UInt32 OnChangeDictionary();
|
||||
void OnChangeSettings();
|
||||
public:
|
||||
CProgressSyncInfo _syncInfo;
|
||||
|
||||
CBenchmarkDialog(): _timer(0) {}
|
||||
INT_PTR Create(HWND wndParent = 0) { return CModalDialog::Create(IDD_DIALOG_BENCHMARK, wndParent); }
|
||||
};
|
||||
|
||||
HRESULT Benchmark(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs,
|
||||
#endif
|
||||
UInt32 dictionarySize, UInt32 numThreads);
|
||||
|
||||
#endif
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#define _WIN32_WINNT 0x0400
|
||||
|
||||
// it's for Windows NT supporting (MENUITEMINFOW)
|
||||
#define WINVER 0x0400
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#include "Common/NewHandler.h"
|
||||
|
||||
#endif
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#define IDD_DIALOG_BENCHMARK 800
|
||||
#define IDC_BUTTON_STOP 1001
|
||||
#define IDC_BUTTON_RESTART 1002
|
||||
#define IDC_BENCHMARK_DICTIONARY 1010
|
||||
#define IDC_BENCHMARK_COMBO_DICTIONARY 1011
|
||||
#define IDC_BENCHMARK_MEMORY 1012
|
||||
#define IDC_BENCHMARK_MEMORY_VALUE 1013
|
||||
#define IDC_BENCHMARK_NUM_THREADS 1014
|
||||
#define IDC_BENCHMARK_COMBO_NUM_THREADS 1015
|
||||
#define IDC_BENCHMARK_HARDWARE_THREADS 1016
|
||||
|
||||
#define IDC_BENCHMARK_SPEED_LABEL 1020
|
||||
#define IDC_BENCHMARK_RATING_LABEL 1021
|
||||
#define IDC_BENCHMARK_COMPRESSING 1022
|
||||
#define IDC_BENCHMARK_DECOMPRESSING 1023
|
||||
#define IDC_BENCHMARK_CURRENT 1024
|
||||
#define IDC_BENCHMARK_RESULTING 1025
|
||||
#define IDC_BENCHMARK_CURRENT2 1026
|
||||
#define IDC_BENCHMARK_RESULTING2 1027
|
||||
#define IDC_BENCHMARK_USAGE_LABEL 1028
|
||||
#define IDC_BENCHMARK_RPU_LABEL 1029
|
||||
|
||||
#define IDC_BENCHMARK_COMPRESSING_SPEED 1030
|
||||
#define IDC_BENCHMARK_COMPRESSING_SPEED2 1031
|
||||
#define IDC_BENCHMARK_COMPRESSING_RATING 1032
|
||||
#define IDC_BENCHMARK_COMPRESSING_RATING2 1033
|
||||
#define IDC_BENCHMARK_COMPRESSING_USAGE 1034
|
||||
#define IDC_BENCHMARK_COMPRESSING_USAGE2 1035
|
||||
#define IDC_BENCHMARK_COMPRESSING_RPU 1036
|
||||
#define IDC_BENCHMARK_COMPRESSING_RPU2 1037
|
||||
|
||||
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_SPEED 1040
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_SPEED2 1041
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_RATING 1042
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_RATING2 1043
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_USAGE 1044
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_USAGE2 1045
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_RPU 1046
|
||||
#define IDC_BENCHMARK_DECOMPRESSING_RPU2 1047
|
||||
|
||||
|
||||
#define IDC_BENCHMARK_TOTAL_RATING 1050
|
||||
|
||||
#define IDC_BENCHMARK_TOTAL_RATING_VALUE 1051
|
||||
#define IDC_BENCHMARK_TOTAL_RPU_VALUE 1052
|
||||
#define IDC_BENCHMARK_TOTAL_USAGE_VALUE 1053
|
||||
|
||||
#define IDC_BENCHMARK_ELAPSED 1060
|
||||
#define IDC_BENCHMARK_ELAPSED_VALUE 1061
|
||||
#define IDC_BENCHMARK_SIZE 1062
|
||||
#define IDC_BENCHMARK_SIZE_VALUE 1063
|
||||
#define IDC_BENCHMARK_PASSES 1066
|
||||
#define IDC_BENCHMARK_PASSES_VALUE 1067
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
#include "resource.h"
|
||||
#include "../../../../GuiCommon.rc"
|
||||
|
||||
#define xSize2 330
|
||||
#define ySize2 228
|
||||
|
||||
#define xSize (xSize2 + marg + marg)
|
||||
#define ySize (ySize2 + marg + marg)
|
||||
|
||||
#undef g0XSize
|
||||
#undef g1XPos
|
||||
#undef g1XSize
|
||||
#undef g2XSize
|
||||
#undef g3XPos
|
||||
#undef g3XSize
|
||||
|
||||
#define bXPos1 (xSize - marg - bXSize)
|
||||
#define bXPos2 (bXPos1 - 10 - bXSize)
|
||||
|
||||
#define bYPos (ySize - marg - bYSize)
|
||||
|
||||
#define gSize 160
|
||||
#define gSpace 24
|
||||
|
||||
#define g0XSize 90
|
||||
#define g1XSize 44
|
||||
#define g1XPos (marg + g0XSize)
|
||||
#define gc2XPos (g1XPos + g1XSize + 10)
|
||||
#define gc2XSize 80
|
||||
|
||||
#define g10XPos (marg + marg)
|
||||
|
||||
#define gRatingSize 60
|
||||
#define gSpeedSize 60
|
||||
#define gUsageSize 60
|
||||
#define gRpuSize 60
|
||||
|
||||
#define gRatingPos (xSize - marg - marg - gRatingSize)
|
||||
#define gRpuPos (gRatingPos - gRpuSize)
|
||||
#define gUsagePos (gRpuPos - gUsageSize)
|
||||
#define gSpeedPos (gUsagePos - gSpeedSize)
|
||||
|
||||
#define gLabelSize (gUsagePos - g10XPos)
|
||||
#define gTotalRatingSize (gUsageSize + gRpuSize + gRatingSize + marg + marg)
|
||||
#define gTotalRatingPos (xSize - marg - gTotalRatingSize)
|
||||
|
||||
#define g2XSize 58
|
||||
#define g3XSize 36
|
||||
#define g3XPos (marg + g2XSize)
|
||||
|
||||
|
||||
IDD_DIALOG_BENCHMARK DIALOG 0, 0, xSize, ySize MY_MODAL_DIALOG_STYLE | WS_MINIMIZEBOX
|
||||
CAPTION "Benchmark"
|
||||
MY_FONT
|
||||
BEGIN
|
||||
PUSHBUTTON "&Restart", IDC_BUTTON_RESTART, bXPos1, marg, bXSize, bYSize
|
||||
PUSHBUTTON "&Stop", IDC_BUTTON_STOP, bXPos1, 27, bXSize, bYSize
|
||||
|
||||
PUSHBUTTON "&Help", IDHELP, bXPos2, bYPos, bXSize,bYSize
|
||||
PUSHBUTTON "Cancel", IDCANCEL, bXPos1, bYPos, bXSize, bYSize
|
||||
|
||||
LTEXT "&Dictionary size:", IDC_BENCHMARK_DICTIONARY, marg, marg + 1, g0XSize, 8
|
||||
COMBOBOX IDC_BENCHMARK_COMBO_DICTIONARY, g1XPos, marg, g1XSize, 140, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
|
||||
LTEXT "&Number of CPU threads:", IDC_BENCHMARK_NUM_THREADS, marg, 24, g0XSize, 8
|
||||
COMBOBOX IDC_BENCHMARK_COMBO_NUM_THREADS, g1XPos, 23, g1XSize, 140, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
|
||||
LTEXT "Memory usage:", IDC_BENCHMARK_MEMORY, gc2XPos, marg + 1, gc2XSize, 8
|
||||
LTEXT "0 MB", IDC_BENCHMARK_MEMORY_VALUE, gc2XPos + gc2XSize, marg + 1, 40, 8
|
||||
LTEXT "1", IDC_BENCHMARK_HARDWARE_THREADS, gc2XPos, 24, 40, 8
|
||||
|
||||
RTEXT "CPU Usage", IDC_BENCHMARK_USAGE_LABEL, gUsagePos, 53, gUsageSize, 8
|
||||
RTEXT "Speed", IDC_BENCHMARK_SPEED_LABEL, gSpeedPos, 53, gSpeedSize, 8
|
||||
RTEXT "Rating / Usage", IDC_BENCHMARK_RPU_LABEL, gRpuPos, 53, gRpuSize, 8
|
||||
RTEXT "Rating", IDC_BENCHMARK_RATING_LABEL, gRatingPos, 53, gRatingSize, 8
|
||||
|
||||
GROUPBOX "Compressing", IDC_BENCHMARK_COMPRESSING, marg, 64, xSize2, 40
|
||||
|
||||
LTEXT "Current", IDC_BENCHMARK_CURRENT, g10XPos, 76, gLabelSize, 8
|
||||
RTEXT "100%", IDC_BENCHMARK_COMPRESSING_USAGE, gUsagePos, 76, gUsageSize, 8
|
||||
RTEXT "100 KB/s", IDC_BENCHMARK_COMPRESSING_SPEED, gSpeedPos, 76, gSpeedSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_COMPRESSING_RPU, gRpuPos, 76, gRpuSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_COMPRESSING_RATING, gRatingPos, 76, gRatingSize, 8
|
||||
|
||||
LTEXT "Resulting", IDC_BENCHMARK_RESULTING, g10XPos, 89, gLabelSize, 8
|
||||
RTEXT "100%", IDC_BENCHMARK_COMPRESSING_USAGE2, gUsagePos, 89, gUsageSize, 8
|
||||
RTEXT "100 KB/s", IDC_BENCHMARK_COMPRESSING_SPEED2, gSpeedPos, 89, gSpeedSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_COMPRESSING_RPU2, gRpuPos, 89, gRpuSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_COMPRESSING_RATING2, gRatingPos, 89, gRatingSize, 8
|
||||
|
||||
GROUPBOX "Decompressing", IDC_BENCHMARK_DECOMPRESSING, marg, 111, xSize2, 40
|
||||
|
||||
LTEXT "Current", IDC_BENCHMARK_CURRENT2, g10XPos, 123, gLabelSize, 8
|
||||
RTEXT "100%", IDC_BENCHMARK_DECOMPRESSING_USAGE, gUsagePos, 123, gUsageSize, 8
|
||||
RTEXT "100 KB/s", IDC_BENCHMARK_DECOMPRESSING_SPEED, gSpeedPos, 123, gSpeedSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_DECOMPRESSING_RPU, gRpuPos, 123, gRpuSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_DECOMPRESSING_RATING, gRatingPos, 123, gRatingSize, 8
|
||||
|
||||
LTEXT "Resulting", IDC_BENCHMARK_RESULTING2, g10XPos, 136, gLabelSize, 8
|
||||
RTEXT "100%", IDC_BENCHMARK_DECOMPRESSING_USAGE2, gUsagePos, 136, gUsageSize, 8
|
||||
RTEXT "100 KB/s", IDC_BENCHMARK_DECOMPRESSING_SPEED2, gSpeedPos, 136, gSpeedSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_DECOMPRESSING_RPU2, gRpuPos, 136, gRpuSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_DECOMPRESSING_RATING2, gRatingPos, 136, gRatingSize, 8
|
||||
|
||||
GROUPBOX "Total Rating", IDC_BENCHMARK_TOTAL_RATING, gTotalRatingPos, 163, gTotalRatingSize, 38
|
||||
RTEXT "0", IDC_BENCHMARK_TOTAL_USAGE_VALUE, gUsagePos, 181, gUsageSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_TOTAL_RPU_VALUE, gRpuPos, 181, gRpuSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_TOTAL_RATING_VALUE, gRatingPos, 181, gRatingSize, 8
|
||||
|
||||
LTEXT "Elapsed time:", IDC_BENCHMARK_ELAPSED, marg, 163, g2XSize, 8
|
||||
LTEXT "Size:", IDC_BENCHMARK_SIZE, marg, 176, g2XSize, 8
|
||||
LTEXT "Passes:", IDC_BENCHMARK_PASSES, marg, 189, g2XSize, 8
|
||||
RTEXT "00:00:00", IDC_BENCHMARK_ELAPSED_VALUE, g3XPos, 163, g3XSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_SIZE_VALUE, g3XPos, 176, g3XSize, 8
|
||||
RTEXT "0", IDC_BENCHMARK_PASSES_VALUE, g3XPos, 189, g3XSize, 8
|
||||
END
|
||||
Reference in New Issue
Block a user