#include <iostream>
#include <string>
#include <Windows.h>
using
namespace
std;
#define ARRSIZE 100000
class
Vectorization
{
private
:
int
mWorkCount;
__int64
mTotalVectorTime;
__int64
mTotalNoVectorTime;
__int64
mNowVectorTime;
__int64
mNowNoVectorTime;
float
mMinImproveTime;
float
mMaxImproveTime;
int
mPerformDecreseCase;
int
mPerformIncreseCase;
int
mTotalWorkCount;
public
:
Vectorization() : mWorkCount(0), mTotalVectorTime(0), mTotalNoVectorTime(0),
mNowVectorTime(0), mNowNoVectorTime(0), mMinImproveTime(0.f), mMaxImproveTime(0.f),
mPerformDecreseCase(0), mPerformIncreseCase(0), mTotalWorkCount(0)
{}
void
CalculateWorkTime(
float
* a,
float
* b,
int
arrsize,
bool
isVector)
{
__int64
t1;
__int64
t2;
for
(
int
i = 0; i < arrsize; i++)
{
a[i] = b[i] = i;
}
QueryPerformanceCounter((LARGE_INTEGER*)&t1);
if
(isVector)
{
#pragma loop(vector)
for
(
int
i = 0; i < arrsize; i++)
{
a[i] += b[i];
}
}
else
{
#pragma loop(no_vector)
for
(
int
i = 0; i < arrsize; i++)
{
a[i] += b[i];
}
}
QueryPerformanceCounter((LARGE_INTEGER*)&t2);
if
(isVector)
{
mTotalVectorTime += mNowVectorTime = t2 - t1;
}
else
{
mTotalNoVectorTime += mNowNoVectorTime = t2 - t1;
}
}
void
CalcNowWorkImprovePerform()
{
float
ImproveRate = 100.0f - (
float
)mNowVectorTime / (
float
)mNowNoVectorTime * 100.0f;
if
(ImproveRate < mMinImproveTime)
{
mMinImproveTime = ImproveRate;
}
else
if
(ImproveRate > mMaxImproveTime)
{
mMaxImproveTime = ImproveRate;
}
if
(ImproveRate < 0)
{
mPerformDecreseCase++;
}
else
{
mPerformIncreseCase++;
}
cout <<
"현재 벡터화 작업시간 :: "
<< mNowVectorTime << endl;
cout <<
"현재 비벡터화 작업시간 :: "
<< mNowNoVectorTime << endl;
printf
(
"현재 성능 향상 비율 :: %.2f %%\n\n"
, ImproveRate);
mTotalWorkCount++;
}
void
CalcTotalWorkImprovePerform()
{
float
improveRate = 100.0f - (
float
)mTotalVectorTime / (
float
)mTotalNoVectorTime * 100.0f;
cout <<
"총 벡터화 작업시간 :: "
<< mTotalVectorTime << endl;
cout <<
"총 비벡터화 작업시간 :: "
<< mTotalNoVectorTime << endl << endl;;
printf
(
"최저 성능 향상 비율 :: %.2f %%\n"
, mMinImproveTime);
printf
(
"최고 성능 향상 비율 :: %.2f %%\n"
, mMaxImproveTime);
printf
(
"평균 성능 향상 비율 :: %.2f %%\n\n"
, improveRate);
cout <<
"성능 감소 케이스 :: "
<< mPerformDecreseCase <<
"회"
<< endl;
printf
(
"성능 감소 케이스 비율 :: %.2f %%\n\n"
, (
float
)mPerformDecreseCase / (
float
)mTotalWorkCount * 100.f);
cout <<
"성능 향상 케이스 :: "
<< mPerformIncreseCase <<
"회"
<< endl;
printf
(
"성능 향상 케이스 비율 :: %.2f %%\n\n"
, (
float
)mPerformIncreseCase / (
float
)mTotalWorkCount * 100.f);
cout <<
"총 성능 비교 횟수 :: "
<< mTotalWorkCount <<
"회"
<< endl;
}
};
int
main()
{
Vectorization v;
float
fArr1[ARRSIZE];
float
fArr2[ARRSIZE];
for
(
int
i = 0; i < 10000; i++)
{
v.CalculateWorkTime(fArr1, fArr2, ARRSIZE,
true
);
v.CalculateWorkTime(fArr1, fArr2, ARRSIZE,
false
);
v.CalcNowWorkImprovePerform();
}
v.CalcTotalWorkImprovePerform();
}