本文整理汇总了C++中Stopwatch::format方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::format方法的具体用法?C++ Stopwatch::format怎么用?C++ Stopwatch::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::format方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
Stopwatch stopWatch;
if (argc < 2)
{
cerr << "Missing argument: number of items to insert." << endl;
return 1;
}
int const N = atoi(argv[1]);
size_t* values = new size_t[N];
srand(123456789);
for (int i = 0; i < N; ++i)
{
values[i] = rand();
}
cerr << "Persistent map:" << endl;
stopWatch.start();
Map map;
for (int i = 0; i < N; ++i)
map = map.insert(values[i], i);
cerr << " Time for " << N << " insertions: "
<< stopWatch.format() << endl;
stopWatch.start();
double sumA = 0.0;
for (int i = N / 2; i < N; ++i)
{
sumA += map.getVal(values[i], 0);
}
cerr << " Time for " << N/2 << " queries: "
<< stopWatch.format() << endl;
stopWatch.start();
Map copy = map;
for (int i = 0; i < N; i += 2)
copy = copy.remove(values[i]);
cerr << " Time for " << N/2 << " removals: "
<< stopWatch.format() << endl;
cerr << endl;
cerr << "Boost unordered_map:" << endl;
stopWatch.start();
unordered_map<int, int> bmap;
for (int i = 0; i < N; ++i)
bmap[values[i]] = i;
cerr << " Time for " << N << " insertions: "
<< stopWatch.format() << endl;
stopWatch.start();
double sumB = 0.0;
for (int i = N / 2; i < N; ++i)
{
sumB += bmap.at(values[i]);
}
cerr << " Time for " << N/2 << " queries: "
<< stopWatch.format() << endl;
stopWatch.start();
for (int i = 0; i < N; i += 2)
bmap.erase(values[i]);
cerr << " Time for " << N/2 << " removals: "
<< stopWatch.format() << endl;
if (sumA != sumB)
cerr << "Sums don't match!" << endl;
return 0;
}