本文介绍了如何在C ++ Linux中测量任务的确切cpucycles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我正在Linux上使用C ++进行工作,我想找到执行任务所用的确切cpucycles数量,但是每当我运行代码时,我都会得到不同的cpucycles值.我可以将cpucycles转换为实际执行时间.我还在下面附加了我的代码.

在此先感谢
问候,
伊什蒂亚克

#include<stdio.h>

static __inline__ unsigned long long rdtsc(void)
{
  unsigned long long int x;
     __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
     return x;
}


int main() {
    	unsigned long long cycles = rdtsc(); //1
    	cycles = rdtsc() - cycles;           //2


    printf("Time is %d\n", (unsigned)cycles);

    return 0;
}
解决方案



Dear All,
I am working on C++ in Linux and I want to find the exact number of cpucycles used my task for execution.But whenever I run my code I get different value of cpucycles.How I can find the exact cpucycles used by my task.Also how I can convert cpucycles to actual execution time.I have also appended my code below.

Thanks in advance
Regards,
Ishtiaq

#include<stdio.h>

static __inline__ unsigned long long rdtsc(void)
{
  unsigned long long int x;
     __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
     return x;
}


int main() {
    	unsigned long long cycles = rdtsc(); //1
    	cycles = rdtsc() - cycles;           //2


    printf("Time is %d\n", (unsigned)cycles);

    return 0;
}
解决方案




这篇关于如何在C ++ Linux中测量任务的确切cpucycles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 04:29