C语言计算代码执行所耗CPU时钟周期

内容摘要
该代码受乱序执行等影响, 需要sync


LARGE_INTEGER _start = { 0 }, _end = { 0 };
__asm{
rdtsc
mov dword ptr [_start.LowPart], eax
mov dword ptr[_start.HighP
文章正文

该代码受乱序执行等影响, 需要sync

LARGE_INTEGER _start = { 0 }, _end = { 0 };
__asm{
  rdtsc
  mov dword ptr [_start.LowPart], eax
  mov dword ptr[_start.HighPart], edx
}
 
//your code here
 
__asm{
  rdtsc
  mov dword ptr [_end.LowPart], eax
  mov dword ptr[_end.HighPart], edx
}
 
long interval = static_cast<long>(_end.QuadPart - _start.QuadPart);

以上就是本文分享的全部内容了,希望小伙伴们能够喜欢。


代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!