class CTest
{
public:
enum{
TABLESIZE = 100,
};
int m_Table[TABLESIZE];
public:
CTest();
int CaseGoto();
int CaseTry();
virtual void OnExcept(){}
};
CTest::CTest()
{
::memset(m_Table,0,sizeof(m_Table));
m_Table[0] = 1;
}
int CTest::CaseGoto()
{
int nCount = 0;
for(int i=0; i<1000000; i++ ){
for(int x=0; x<TABLESIZE; x++ ){
if( m_Table[x] != 0 ){
OnExcept(); // 最適化されないように念のため
goto next; // throwと比較しやすいようにgoto使ってます
}
}
nCount++;
next:;
}
return nCount;
}
int CTest::CaseTry()
{
int nCount = 0;
for(int i=0; i<1000000; i++ ){
try{
for(int x=0; x<TABLESIZE; x++ ){
if( m_Table[x] != 0 ){
OnExcept(); // 最適化されないように念のため
throw false;
}
}
nCount++;
}catch(...){
}
}
return nCount;
}
|