mirror of https://github.com/x64dbg/zydis
Improved performance-test tool
This commit is contained in:
parent
606214c5a7
commit
8540326e33
|
@ -39,6 +39,7 @@
|
||||||
# include <mach/mach_time.h>
|
# include <mach/mach_time.h>
|
||||||
#elif defined(ZYDIS_LINUX)
|
#elif defined(ZYDIS_LINUX)
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
|
# inlcude <pthread.h>
|
||||||
#else
|
#else
|
||||||
# error "Unsupported platform detected"
|
# error "Unsupported platform detected"
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,6 +48,10 @@
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
/* ============================================================================================== */
|
/* ============================================================================================== */
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
/* Time measurement */
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#if defined(ZYDIS_WINDOWS)
|
#if defined(ZYDIS_WINDOWS)
|
||||||
double CounterFreq = 0.0;
|
double CounterFreq = 0.0;
|
||||||
uint64_t CounterStart = 0;
|
uint64_t CounterStart = 0;
|
||||||
|
@ -93,6 +98,42 @@ double GetCounter()
|
||||||
// TODO:
|
// TODO:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
/* Process & Thread Priority */
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void adjustProcessAndThreadPriority()
|
||||||
|
{
|
||||||
|
#ifdef ZYDIS_WINDOWS
|
||||||
|
SYSTEM_INFO info;
|
||||||
|
GetSystemInfo(&info);
|
||||||
|
if (info.dwNumberOfProcessors > 1)
|
||||||
|
{
|
||||||
|
if (!SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR)1))
|
||||||
|
{
|
||||||
|
fputs("Warning: Could not set thread affinity mask.", stderr);
|
||||||
|
}
|
||||||
|
if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS))
|
||||||
|
{
|
||||||
|
fputs("Warning: Could not set process priority class.", stderr);
|
||||||
|
}
|
||||||
|
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
|
||||||
|
{
|
||||||
|
fputs("Warning: Could not set thread priority class.", stderr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef ZYDIS_LINUX
|
||||||
|
pthread_t thread = pthread_self();
|
||||||
|
cpu_set_t cpus;
|
||||||
|
CPU_ZERO(&cpus);
|
||||||
|
CPU_SET(cpu, &cpus);
|
||||||
|
pthread_setaffinity_np(thread, sizeof(cpus), &cpus);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* ============================================================================================== */
|
/* ============================================================================================== */
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
/* ============================================================================================== */
|
/* ============================================================================================== */
|
||||||
|
@ -150,6 +191,10 @@ uint64_t processBuffer(const char* buffer, size_t length, ZydisDecodeGranularity
|
||||||
void testPerformance(const char* buffer, size_t length, ZydisDecodeGranularity granularity,
|
void testPerformance(const char* buffer, size_t length, ZydisDecodeGranularity granularity,
|
||||||
ZydisBool format)
|
ZydisBool format)
|
||||||
{
|
{
|
||||||
|
// Cache warmup
|
||||||
|
processBuffer(buffer, length, granularity, format);
|
||||||
|
|
||||||
|
// Testing
|
||||||
uint64_t count = 0;
|
uint64_t count = 0;
|
||||||
StartCounter();
|
StartCounter();
|
||||||
for (uint8_t j = 0; j < 100; ++j)
|
for (uint8_t j = 0; j < 100; ++j)
|
||||||
|
@ -286,9 +331,11 @@ int main(int argc, char** argv)
|
||||||
if (generate)
|
if (generate)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
srand((unsigned) time(&t));
|
srand((unsigned)time(&t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adjustProcessAndThreadPriority();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < ZYDIS_ARRAY_SIZE(tests); ++i)
|
for (uint8_t i = 0; i < ZYDIS_ARRAY_SIZE(tests); ++i)
|
||||||
{
|
{
|
||||||
FILE* file;
|
FILE* file;
|
||||||
|
|
Loading…
Reference in New Issue