Cpp*_*ner 10 c++ performance intel performancecounter
我在网上采用了衡量SSE绩效的方法.
#ifndef __TIMER_H__
#define __TIMER_H__
#pragma warning (push)
#pragma warning (disable : 4035) // disable no return value warning
__forceinline unsigned int GetPentiumTimer()
{
__asm
{
xor eax,eax // VC won't realize that eax is modified w/out this
// instruction to modify the val.
// Problem shows up in release mode builds
_emit 0x0F // Pentium high-freq counter to edx;eax
_emit 0x31 // only care about low 32 bits in eax
xor edx,edx // so VC gets that edx is modified
}
}
#pragma warning (pop)
#endif
Run Code Online (Sandbox Code Playgroud)
我在我的Pentium D E2200 CPU上进行了测量,它工作正常(它显示对齐的SSE指令更快).但是在我的i3 CPU上,我得到了70%的测试更快的未对齐指令.
你们觉得这个时钟滴答测量不适合i3 CPU吗?
QueryPerformanceCounter(至少在 Windows 上)绝对比内联汇编好得多。我看不出有任何理由在该函数上使用内联汇编(这会给您在不支持内联汇编的 Visual Studio 上编译为 x64 带来问题)。