TNB Library
TnbDiskBenchMark.h
[詳解]
1#pragma once
11#include "TnbTemporaryFile.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
32{
33 CTemporaryFile m_tempFile;
34
35public:
36
39 {
40 }
41
49 DWORD SetTarget(TCHAR drv, size_t size)
50 {
51 try
52 {
53 CStr s;
54 s.Format(_T("%c:"), drv);
55 m_tempFile.Free();
56 m_tempFile.SetTempraryFolder(s);
57 m_tempFile.Create(size);
58 }
59 catch ( CIoFailureException& e )
60 {
61 return e.GetParam();
62 }
63 return 0;
64 }
65
73 DWORD ReadTest(DWORD time, size_t one = 1024) const
74 {
75 if ( time == 0 ) { return DWORD_MAX; }
76 if ( ! m_tempFile.HasThat() )
77 {
78 return DWORD_MAX;
79 }
80 CStr file = m_tempFile.GetName();
81 HANDLE h = ::CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
82 if ( h == INVALID_HANDLE_VALUE )
83 {
84 return DWORD_MAX;
85 }
86 ULONGLONG total = 0;
87 DWORD startTick = ::GetTickCount();
88 DWORD dwRead;
89 CWorkMem work(one);
90 BYTE* B = work.Ref();
91 while ( true )
92 {
93 dwRead = 0;
94 if ( ! ::ReadFile(h, B, ToDword(one), &dwRead, NULL) )
95 {
96 total = DWORD_MAX;
97 break;
98 }
99 DWORD nowTick = ::GetTickCount();
100 DWORD d = nowTick - startTick;
101 total += dwRead;
102 if ( d >= time )
103 {
104// TRACE2("read %dKB / %dms\n", (DWORD)(total / 1024), d);
105 total *= 1000;
106 total /= d;
107 break;
108 }
109 if ( dwRead != one )
110 {
111 ::SetFilePointer(h, 0, NULL, FILE_BEGIN);
112 }
113 }
114 ::CloseHandle(h);
115 return static_cast<DWORD>(total);
116 }
117
118
119
120
121
122
123private :
124 friend class CDiskBenchMarkTest;
125};
126
127
128
129}; // TNB
テンポラリファイル関係のヘッダ
[ETC] コピー不可能スーパークラス.
Definition: TnbDef.h:599
ベンチマーククラス
CDiskBenchMark(void)
‍テンポラリファイル
DWORD SetTarget(TCHAR drv, size_t size)
[設定] ターゲット設定
DWORD ReadTest(DWORD time, size_t one=1024) const
[処理] 読込みテスト
読み書き失敗発生例外
Definition: TnbException.h:212
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
Definition: TnbStr.h:359
bool HasThat(void) const
[確認] テンポラリファイル有無確認
void SetTempraryFolder(LPCTSTR pFolder)
[設定] テンポラリフォルダ指定.
CStr GetName(void) const
[取得] テンポラリファイル名取得
CStr Create(void)
[操作] 作成.
void Free(void)
[操作] 解放.
DWORD GetParam(void) const
[取得] パラメータ取得
Definition: TnbException.h:58
const TYP * Ref(void) const
[取得] ポインタ取得
Definition: TnbDef.h:712
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
Definition: TnbStrLib.h:395
TNB Library
Definition: TnbDoxyTitle.txt:2