小编use*_*106的帖子

使用RDTSC获取cpu周期 - 为什么RDTSC的值总是增加?

我想在特定点获得CPU周期.我在这一点上使用这个功能:

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

问题是它总是返回一个增加的数字(在每次运行中).就好像它指的是绝对时间.

我错误地使用了这些功能吗?

linux x86 assembly cpu-usage

16
推荐指数
2
解决办法
3万
查看次数

如何减去两个gettimeofday实例?

我想减去两个gettimeofday实例,并以毫秒为单位显示答案.

这个想法是:

  static struct timeval tv;
  gettimeofday(&tv, NULL);

  static struct timeval tv2;
  gettimeofday(&tv2, NULL);

  static struct timeval tv3=tv2-tv;
Run Code Online (Sandbox Code Playgroud)

然后将'tv3'转换为毫秒分辨率.

c++ linux gettimeofday

3
推荐指数
1
解决办法
6913
查看次数

使用"ifstream"时出现分段错误

我正试图在文件中获取部分文本.我用过"ifstream":

#include <fstream>

void func(){
    char *myString;

    ifstream infile;
    infile.open("/proc/cpuinfo");

    while (infile >> myString){
        if  (!strcmp(myString,"MHz"))
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个"分段错误".有谁知道为什么?

c++ ifstream segmentation-fault

1
推荐指数
1
解决办法
7629
查看次数

使用char*而不是字符串c ++逐行读取文本文件

我有下一个代码:

  std::string line;
  std::ifstream myfile ("text.txt");
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      std::cout << line << std::endl;
    }
    myfile.close();
  }
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点,并使用char*而不是字符串?

c++

1
推荐指数
1
解决办法
3255
查看次数

函数atof()将其结果舍入为整数部分

为什么圆形"14718.5084"到14718.5?有没有办法防止这种情况(即得到整数14718.5084)?

码:

double latitude=atof("14718.5084");
std::cout <<"latitude test "<<latitude<< "\n";
Run Code Online (Sandbox Code Playgroud)

输出是:

latitude test 14718.5
Run Code Online (Sandbox Code Playgroud)

谢谢

c++ atof

0
推荐指数
1
解决办法
3881
查看次数