Skip to content

Instantly share code, notes, and snippets.

@LukeUsher
Created December 12, 2016 21:15
Show Gist options
  • Save LukeUsher/85a6360012d6bdbd90d2f243f1d1752a to your computer and use it in GitHub Desktop.
Save LukeUsher/85a6360012d6bdbd90d2f243f1d1752a to your computer and use it in GitHub Desktop.
Minimal exception speed test case
#include <Windows.h>
#include <iostream>
// exception handler
int EmuException(LPEXCEPTION_POINTERS e)
{
// Increment EIP to skip the faulting instruction
e->ContextRecord->Eip += 1;
return EXCEPTION_CONTINUE_EXECUTION;
}
int main(int argc, char* argv[])
{
int number = 0;
int iterations = 1000000;
__try {
std::cout << "Timing " << iterations << " iterations with No Exceptions" << std::endl;
ULONGLONG start = GetTickCount64();
for (int i = 0; i < iterations; i++) {
number++;
}
std::cout << "Execution took " << (GetTickCount64() - start) << "ms" << std::endl;
number = 0;
start = GetTickCount64();
std::cout << "Timing " << iterations << " iterations with Exceptions" << std::endl;
for (int i = 0; i < iterations; i++) {
_asm{ int 3 };
}
std::cout << "Execution took " << (GetTickCount64() - start) << "ms" << std::endl;
} __except (EmuException(GetExceptionInformation()))
{
printf("Emu: WARNING!! Problem with ExceptionFilter\n");
}
std::cout << "Completed!";
for (;;);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment