我正在使用boost 1.59.0。
我正在尝试使用boost :: chrono :: process_cpu_clock来计算我的代码块。我想以毫秒为单位报告此时间,而不是纳秒。我想使用duration_cast模板函数,虽然我只找到了将一个持续时间值作为参数的示例,而不是process_cpu_clock.now()返回的三个值的元组。
以下是我写的代码:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main(){
//Changecase to Uppercase
string var = "This is a String.";
for (unsigned int i = 0; i < var.length(); i++){
if (islower(var[i]))
var[i] = toupper(var[i]);
}
cout << var << endl;
/*
Output:
THIS IS A STRING.
*/
//Changecase to Lowercase
var = "This is a String.";
for (unsigned int i = 0; i < var.length(); i++){
if (isupper(var[i]))
var[i] = tolower(var[i]);
}
cout << var << endl;
/*
Output:
this is a string.
*/
//Flip the case
var = "This is a String.";
for (unsigned int i = 0; i < var.length(); i++){
if (isupper(var[i]))
var[i] = tolower(var[i]);
else
var[i] = toupper(var[i]);
}
cout << var << endl;
/*
Output:
tHIS IS A sTRING.
*/
system("pause");
return 0;
}
chrono::process_cpu_clock mytimer;
const auto start = mytimer.now();
// do work
const auto duration = mytimer.now() - start;
const auto duration_msec = duration_cast<milliseconds>(duration);
与duration_msec
完全相同;它没有转换为毫秒。
也许duration_cast不打算将process_cpu_clock :: duration类型作为参数;但是,它编译好了。
我做错了什么?