Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
読み取り中…
検索中…
一致する文字列を見つけられません
NewPerformanceCheck.cpp
[詳解]
1
5
6#include "pch.h"
8
9using namespace PerfCheck;
10
12 :PerformanceCheck (console)
13{
14}
15
17{
18}
19
21{
22 return this->Core (0);
23}
24
25BOOL NewPerformanceCheck::Core (const int param1)
26{
28
29 auto threadFunc = [](LPVOID lpvParam)->DWORD
30 {
32 alt::Event event;
33 int loop = me->_loop;
34
35 event.Open (_T ("START_EVENT"));
36 event.Wait ();
37
38 OutputDebugString (_T ("Thread action is started.\n"));
39 do
40 {
41 int index = rand () % 10;
42 TCHAR tsz[10];
43 wsprintf (tsz, _T ("%d(%d),"), GetCurrentThreadId (), index);
44 OutputDebugString (tsz);
45
46 LPVOID lpvMem = new BYTE[me->_allocSize[index]];
47 ZeroMemory (lpvMem, me->_allocSize[index]);
48
49 delete[] lpvMem;
50
51 } while (--loop);
52 OutputDebugString (_T ("Thread action is stopped.\n"));
53
54 return 0;
55 };
56
57 alt::Event event;
58 event.Create (_T ("START_EVENT"), TRUE, FALSE);
59 _console.Write (_T ("Event作成\n"));
60
61 const int numOfThreads = 48;
62 this->_loop = 50000;
63
64 alt::Thread thread[numOfThreads];
65 for (auto& item : thread)
66 {
67 item.Create (threadFunc, (LPVOID)this);
68 SwitchToThread ();
69 }
70 _console.Write (_T ("Thread作成\n"));
71
72 HANDLE threadHandles[numOfThreads];
73 for (int i = 0; i < numOfThreads; i++)
74 {
75 threadHandles[i] = thread[i].GetHandle ();
76 }
77 _console.Write (_T ("Thread Handle収集\n"));
78
79 _console.Write (_T ("計測開始\n"));
80 Q.Start ();
81
82 event.Set ();
83 WaitForMultipleObjects (numOfThreads, threadHandles, TRUE, INFINITE);
84
85 Q.Stop ();
86 _console.Write (_T ("計測終了\n"));
87
88 int msec = static_cast<int>(Q.PastTime ());
89
90 _console.Format( _T ("It takes %dmsec.\n"), msec);
91
92 return TRUE;
93}
newの性能測定用
#define loop
プリコンパイル済みヘッダー ファイルです。
virtual BOOL Core(const int param1)
NewPerformanceCheck(alt::Console &console)
virtual BOOL DoAction()
処理開始
コンソールに関するクラス
Definition: Console.h:88
DWORD APIENTRY Write(LPCTSTR lpctszString) const
コンソールに文字を出力します。
Definition: Console.cpp:54
VOID APIENTRY Format(LPCTSTR format,...) const
コンソールに文字を出力します。
Definition: Console.cpp:63
イベントに関するWindowsAPIを集約したクラス
Definition: Event.h:16
BOOL APIENTRY Create(LPCTSTR lpctszName, BOOL bManualReset, BOOL bInitialState)
イベントを作成します。
Definition: Event.cpp:12
HANDLE APIENTRY GetHandle() const
継承先はこの関数でハンドルを取得します。
高分解能時間計測クラス
VOID APIENTRY Start()
計測を開始します。
double APIENTRY PastTime() const
計測開始〜計測終了までの時間を出力します。
VOID APIENTRY Stop()
計測を終了します。
スレッドに関するWindowsAPIを集約したクラス
Definition: Thread.h:43
BOOL APIENTRY Create(PTHREAD_START_ROUTINE function=NULL, LPVOID lpvParam=NULL, DWORD dwCreationFlag=0)
スレッドを作成します。
Definition: Thread.cpp:24