4.46 beta

This commit is contained in:
Igor Pavlov
2007-05-25 00:00:00 +00:00
committed by Kornel Lesiński
parent a145bfc7cf
commit c574fc0f4b
191 changed files with 1318 additions and 854 deletions

View File

@@ -265,6 +265,14 @@ SOURCE=..\..\..\Windows\Defs.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\IntToString.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\MyCom.h
# End Source File
# Begin Source File

View File

@@ -5,10 +5,28 @@
#include "LzmaBench.h"
#ifndef _WIN32
#include <time.h>
#define USE_POSIX_TIME
#define USE_POSIX_TIME2
#endif
#ifdef USE_POSIX_TIME
#include <time.h>
#ifdef USE_POSIX_TIME2
#include <sys/time.h>
#endif
#endif
#ifdef _WIN32
#define USE_ALLOCA
#endif
#ifdef USE_ALLOCA
#ifdef _WIN32
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#endif
extern "C"
{
@@ -35,12 +53,12 @@ static const UInt32 kAdditionalSize = (1 << 16);
static const UInt32 kCompressedAdditionalSize = (1 << 10);
static const UInt32 kMaxLzmaPropSize = 5;
class CRandomGenerator
class CBaseRandomGenerator
{
UInt32 A1;
UInt32 A2;
public:
CRandomGenerator() { Init(); }
CBaseRandomGenerator() { Init(); }
void Init() { A1 = 362436069; A2 = 521288629;}
UInt32 GetRnd()
{
@@ -75,9 +93,9 @@ public:
class CBenchRandomGenerator: public CBenchBuffer
{
CRandomGenerator *RG;
CBaseRandomGenerator *RG;
public:
void Set(CRandomGenerator *rg) { RG = rg; }
void Set(CBaseRandomGenerator *rg) { RG = rg; }
UInt32 GetVal(UInt32 &res, int numBits)
{
UInt32 val = res & (((UInt32)1 << numBits) - 1);
@@ -217,49 +235,64 @@ STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *process
static UInt64 GetTimeCount()
{
#ifdef _WIN32
#ifdef USE_POSIX_TIME
#ifdef USE_POSIX_TIME2
timeval v;
if (gettimeofday(&v, 0) == 0)
return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;
return (UInt64)time(NULL) * 1000000;
#else
return time(NULL);
#endif
#else
/*
LARGE_INTEGER value;
if (::QueryPerformanceCounter(&value))
return value.QuadPart;
*/
return GetTickCount();
#else
return clock();
#endif
}
static UInt64 GetFreq()
{
#ifdef _WIN32
#ifdef USE_POSIX_TIME
#ifdef USE_POSIX_TIME2
return 1000000;
#else
return 1;
#endif
#else
/*
LARGE_INTEGER value;
if (::QueryPerformanceFrequency(&value))
return value.QuadPart;
*/
return 1000;
#else
return CLOCKS_PER_SEC;
#endif
}
UInt64 GetUserTime()
#ifndef USE_POSIX_TIME
static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }
#endif
static UInt64 GetUserTime()
{
#ifdef _WIN32
FILETIME creationTime, exitTime, kernelTime, userTime;
::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime);
return ((UInt64)userTime.dwHighDateTime << 32) | userTime.dwLowDateTime;
#else
#ifdef USE_POSIX_TIME
return clock();
#else
FILETIME creationTime, exitTime, kernelTime, userTime;
if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)
return GetTime64(userTime) + GetTime64(kernelTime);
return (UInt64)GetTickCount() * 10000;
#endif
}
static UInt64 GetUserFreq()
{
#ifdef _WIN32
return 10000000;
#else
#ifdef USE_POSIX_TIME
return CLOCKS_PER_SEC;
#else
return 10000000;
#endif
}
@@ -435,13 +468,17 @@ struct CEncoderInfo
CBenchProgressInfo *progressInfoSpec[2];
CMyComPtr<ICompressProgressInfo> progressInfo[2];
UInt32 NumIterations;
#ifdef USE_ALLOCA
size_t AllocaSize;
#endif
struct CDecoderInfo
{
CEncoderInfo *Encoder;
UInt32 DecoderIndex;
#ifdef USE_ALLOCA
size_t AllocaSize;
#endif
bool CallbackMode;
};
CDecoderInfo decodersInfo[2];
@@ -457,17 +494,19 @@ struct CEncoderInfo
CBenchRandomGenerator rg;
CBenchmarkOutStream *propStreamSpec;
CMyComPtr<ISequentialOutStream> propStream;
HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CRandomGenerator *rg);
HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);
HRESULT Encode();
HRESULT Decode(UInt32 decoderIndex);
CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}
#ifdef BENCH_MT
static DWORD WINAPI EncodeThreadFunction(void *param)
static THREAD_FUNC_DECL EncodeThreadFunction(void *param)
{
CEncoderInfo *encoder = (CEncoderInfo *)param;
#ifdef USE_ALLOCA
alloca(encoder->AllocaSize);
#endif
HRESULT res = encoder->Encode();
encoder->Results[0] = res;
if (res != S_OK)
@@ -475,38 +514,41 @@ struct CEncoderInfo
return 0;
}
static DWORD WINAPI DecodeThreadFunction(void *param)
static THREAD_FUNC_DECL DecodeThreadFunction(void *param)
{
CDecoderInfo *decoder = (CDecoderInfo *)param;
#ifdef USE_ALLOCA
alloca(decoder->AllocaSize);
#endif
CEncoderInfo *encoder = decoder->Encoder;
encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);
return 0;
}
HRESULT CreateEncoderThread(size_t allocaSize)
HRESULT CreateEncoderThread()
{
AllocaSize = allocaSize;
if (!thread[0].Create(EncodeThreadFunction, this))
return ::GetLastError();
return 0;
return thread[0].Create(EncodeThreadFunction, this);
}
HRESULT CreateDecoderThread(int index, bool callbackMode, size_t allocaSize)
HRESULT CreateDecoderThread(int index, bool callbackMode
#ifdef USE_ALLOCA
, size_t allocaSize
#endif
)
{
CDecoderInfo &decoder = decodersInfo[index];
decoder.DecoderIndex = index;
decoder.Encoder = this;
#ifdef USE_ALLOCA
decoder.AllocaSize = allocaSize;
#endif
decoder.CallbackMode = callbackMode;
if (!thread[index].Create(DecodeThreadFunction, &decoder))
return ::GetLastError();
return 0;
return thread[index].Create(DecodeThreadFunction, &decoder);
}
#endif
};
HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CRandomGenerator *rgLoc)
HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)
{
rg.Set(rgLoc);
kBufferSize = dictionarySize + kAdditionalSize;
@@ -670,7 +712,7 @@ HRESULT LzmaBench(
}
}
CRandomGenerator rg;
CBaseRandomGenerator rg;
rg.Init();
for (i = 0; i < numEncoderThreads; i++)
{
@@ -699,8 +741,10 @@ HRESULT LzmaBench(
#ifdef BENCH_MT
if (numEncoderThreads > 1)
{
size_t allocaSize = (i * 16 * 21) & 0x7FF;
RINOK(encoder.CreateEncoderThread(allocaSize))
#ifdef USE_ALLOCA
encoder.AllocaSize = (i * 16 * 21) & 0x7FF;
#endif
RINOK(encoder.CreateEncoderThread())
}
else
#endif
@@ -753,7 +797,12 @@ HRESULT LzmaBench(
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF;
RINOK(encoder.CreateDecoderThread(j, (i == 0 && j == 0), allocaSize))
HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
#ifdef USE_ALLOCA
, allocaSize
#endif
);
RINOK(res);
}
}
else
@@ -842,7 +891,7 @@ struct CCrcInfo
}
};
static DWORD WINAPI CrcThreadFunction(void *param)
static THREAD_FUNC_DECL CrcThreadFunction(void *param)
{
CCrcInfo *p = (CCrcInfo *)param;
p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);
@@ -876,13 +925,13 @@ static UInt32 CrcCalc1(const Byte *buf, UInt32 size)
return CRC_GET_DIGEST(crc);
}
static void RandGen(Byte *buf, UInt32 size, CRandomGenerator &RG)
static void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
{
for (UInt32 i = 0; i < size; i++)
buf[i] = (Byte)RG.GetRnd();
}
static UInt32 RandGenCrc(Byte *buf, UInt32 size, CRandomGenerator &RG)
static UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
{
RandGen(buf, size, RG);
return CrcCalc1(buf, size);
@@ -903,7 +952,7 @@ bool CrcInternalTest()
UInt32 crc1 = CrcCalc1(buf, kBufferSize0);
if (crc1 != 0x29058C73)
return false;
CRandomGenerator RG;
CBaseRandomGenerator RG;
RandGen(buf + kBufferSize0, kBufferSize1, RG);
for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)
for (UInt32 j = 0; j < kCheckSize; j++)
@@ -925,7 +974,7 @@ HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)
return E_OUTOFMEMORY;
Byte *buf = buffer.Buffer;
CRandomGenerator RG;
CBaseRandomGenerator RG;
UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;
UInt64 timeVal;
@@ -948,8 +997,7 @@ HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)
for (i = 0; i < numThreads; i++)
{
CCrcInfo &info = threads.Items[i];
if (!info.Thread.Create(CrcThreadFunction, &info))
return ::GetLastError();
RINOK(info.Thread.Create(CrcThreadFunction, &info));
threads.NumThreads++;
}
threads.WaitAll();

View File

@@ -6,6 +6,7 @@
#include "LzmaBench.h"
#include "LzmaBenchCon.h"
#include "Common/IntToString.h"
#if defined(BENCH_MT) || defined(_WIN32)
#include "Windows/System.h"
@@ -71,14 +72,24 @@ static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
return value * freq / elTime;
}
static void PrintNumber(FILE *f, UInt64 value, int size)
{
char s[32];
ConvertUInt64ToString(value, s);
fprintf(f, " ");
for (int len = (int)strlen(s); len < size; len++)
fprintf(f, " ");
fprintf(f, "%s", s);
}
static void PrintRating(FILE *f, UInt64 rating)
{
fprintf(f, " %6d", (unsigned int)(rating / 1000000));
PrintNumber(f, rating / 1000000, 6);
}
static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
{
fprintf(f, " %5d", (usage + 5000) / 10000);
PrintNumber(f, (usage + 5000) / 10000, 5);
PrintRating(f, rpu);
PrintRating(f, rating);
}
@@ -87,7 +98,7 @@ static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)
{
UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);
fprintf(f, "%7d", (unsigned int)(speed / 1024));
PrintNumber(f, speed / 1024, 7);
UInt64 usage = GetUsage(info);
UInt64 rpu = GetRatingPerUsage(info, rating);
PrintResults(f, usage, rpu, rating);
@@ -119,7 +130,7 @@ HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
return S_OK;
}
static const char *kSep = " | ";
static const char *kSep = " | ";
HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
@@ -133,17 +144,19 @@ HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
fprintf(f, kSep);
CBenchInfo info2 = info;
info2.GlobalTime /= info.NumIterations;
info2.UserTime /= info.NumIterations;
info2.UnpackSize *= info2.NumIterations;
info2.PackSize *= info2.NumIterations;
info2.NumIterations = 1;
PrintResults(f, info2, rating, DecodeRes);
}
return S_OK;
}
static void PtintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
{
fprintf(f, "\nRAM %s %5d MB, # %s %3d", sizeString,
(unsigned int)(size >> 20), threadsString, (unsigned int)numThreads);
fprintf(f, "\nRAM %s ", sizeString);
PrintNumber(f, (size >> 20), 5);
fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads);
}
HRESULT LzmaBenchCon(
@@ -157,7 +170,7 @@ HRESULT LzmaBenchCon(
#ifdef BENCH_MT
UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
PtintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
if (numThreads == (UInt32)-1)
numThreads = numCPUs;
if (numThreads > 1)
@@ -176,24 +189,24 @@ HRESULT LzmaBenchCon(
numThreads = 1;
#endif
PtintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
CBenchCallback callback;
callback.Init();
callback.f = f;
fprintf(f, "\n\nDict Compressing | Decompressing\n ");
fprintf(f, "\n\nDict Compressing | Decompressing\n ");
int j;
for (j = 0; j < 2; j++)
{
fprintf(f, " Speed Usage R/U Rating");
fprintf(f, " Speed Usage R/U Rating");
if (j == 0)
fprintf(f, kSep);
}
fprintf(f, "\n ");
fprintf(f, "\n ");
for (j = 0; j < 2; j++)
{
fprintf(f, " KB/s %% MIPS MIPS");
fprintf(f, " KB/s %% MIPS MIPS");
if (j == 0)
fprintf(f, kSep);
}
@@ -206,7 +219,7 @@ HRESULT LzmaBenchCon(
pow--;
for (; ((UInt32)1 << pow) <= dictionary; pow++)
{
fprintf(f, "%2d: ", pow);
fprintf(f, "%2d:", pow);
callback.dictionarySize = (UInt32)1 << pow;
HRESULT res = LzmaBench(
#ifdef EXTERNAL_LZMA
@@ -245,7 +258,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic
#ifdef BENCH_MT
UInt64 ramSize = NWindows::NSystem::GetRamSize();
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
PtintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
if (numThreads == (UInt32)-1)
numThreads = numCPUs;
#else
@@ -280,7 +293,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic
return E_ABORT;
#endif
RINOK(CrcBench(ti + 1, bufSize, speed));
fprintf(f, " %5d", (unsigned int)(speed >> 20));
PrintNumber(f, (speed >> 20), 5);
speedTotals.Values[ti] += speed;
}
fprintf(f, "\n");
@@ -291,7 +304,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic
{
fprintf(f, "\nAvg:");
for (UInt32 ti = 0; ti < numThreads; ti++)
fprintf(f, " %5d", (unsigned int)((speedTotals.Values[ti] / numSteps) >> 20));
PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);
fprintf(f, "\n");
}
return S_OK;

View File

@@ -52,6 +52,7 @@ LZMA_OPT_OBJS = \
COMMON_OBJS = \
$O\CommandLineParser.obj \
$O\CRC.obj \
$O\IntToString.obj \
$O\String.obj \
$O\StringConvert.obj \
$O\StringToInt.obj \

View File

@@ -10,27 +10,28 @@ OBJS = \
LzmaBench.o \
LzmaBenchCon.o \
LzmaRam.o \
LzmaRamDecode.o \
LzmaDecode.o \
BranchX86.o \
LZMADecoder.o \
LZMAEncoder.o \
7zCrc.o \
MatchFinder.o \
LZOutWindow.o \
RangeCoderBit.o \
InBuffer.o \
OutBuffer.o \
FileStreams.o \
StreamUtils.o \
Alloc.o \
C_FileIO.o \
CommandLineParser.o \
CRC.o \
IntToString.o \
String.o \
StringConvert.o \
StringToInt.o \
Vector.o \
7zCrc.o \
Alloc.o \
BranchX86.o \
MatchFinder.o \
LzmaDecode.o \
LzmaRamDecode.o \
all: $(PROG)
@@ -50,31 +51,12 @@ LzmaBenchCon.o: LzmaBenchCon.cpp
LzmaRam.o: LzmaRam.cpp
$(CXX) $(CFLAGS) LzmaRam.cpp
LzmaRamDecode.o: LzmaRamDecode.c
$(CXX_C) $(CFLAGS) LzmaRamDecode.c
LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c
BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c
LZMADecoder.o: ../LZMA/LZMADecoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c
7zCrc.o: ../../../../C/7zCrc.c
$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c
Alloc.o: ../../../../Alloc.cpp
$(CXX) $(CFLAGS) ../../../../Alloc.c
LZOutWindow.o: ../LZ/LZOutWindow.cpp
$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
@@ -105,6 +87,9 @@ CRC.o: ../../../Common/CRC.cpp
MyWindows.o: ../../../Common/MyWindows.cpp
$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
IntToString.o: ../../../Common/IntToString.cpp
$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp
String.o: ../../../Common/String.cpp
$(CXX) $(CFLAGS) ../../../Common/String.cpp
@@ -117,6 +102,24 @@ StringToInt.o: ../../../Common/StringToInt.cpp
Vector.o: ../../../Common/Vector.cpp
$(CXX) $(CFLAGS) ../../../Common/Vector.cpp
7zCrc.o: ../../../../C/7zCrc.c
$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c
Alloc.o: ../../../../C/Alloc.c
$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c
BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c
MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c
LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c
LzmaRamDecode.o: LzmaRamDecode.c
$(CXX_C) $(CFLAGS) LzmaRamDecode.c
clean:
-$(RM) $(PROG) $(OBJS)