Created
February 8, 2020 02:45
-
-
Save nibasya/89e00adea6b1c45c508863ea54b2042f to your computer and use it in GitHub Desktop.
SendMessage / PostMessage speed test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UINT __cdecl TestThread(LPVOID pData) | |
{ | |
CMessageSpeedTestDlg* p = static_cast<CMessageSpeedTestDlg*>(pData); | |
QueryPerformanceCounter(&p->m_Begin); | |
p->SendMessage(WM_USER_COMPLETE); | |
return 0; | |
} | |
void CMessageSpeedTestDlg::OnBnClickedButtonStart() | |
{ | |
QueryPerformanceFrequency(&m_Freq); | |
m_Count = 0; | |
m_Sum = 0; | |
CString buffer; | |
m_CtrlEditTarget.GetWindowText(buffer); | |
m_Target = _ttoi(buffer); | |
AfxBeginThread(TestThread, this); | |
} | |
LRESULT CMessageSpeedTestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) | |
{ | |
float time; | |
CString buff; | |
switch (message) { | |
case WM_USER_COMPLETE: | |
QueryPerformanceCounter(&m_End); | |
m_Sum += m_End.QuadPart - m_Begin.QuadPart; | |
time = static_cast<float>(m_Sum) / m_Freq.QuadPart; | |
buff.Format(_T("%d"), m_Count); | |
m_CtrlEditCount.SetWindowText(buff); | |
buff.Format(_T("%f"), time); | |
m_CtrlEditTime.SetWindowText(buff); | |
buff.Format(_T("%f"), time * 1000000 / m_Count); | |
m_CtrlEditAverage.SetWindowText(buff); | |
if (m_Count < m_Target) { | |
m_Count++; | |
AfxBeginThread(TestThread, this); | |
} | |
break; | |
default: | |
break; | |
} | |
return CDialogEx::WindowProc(message, wParam, lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment