C++ 耗时统计代码片段

2023-10-21 16:26:55 浏览数 (2)

C 耗时统计代码片段

代码语言:javascript复制
#include <iostream>
#include <chrono>

typedef std::chrono::milliseconds ms;
using clk = std::chrono::system_clock;

void do_my_work() {
    // work code here

}

int main() {
	auto begin_time = clk::now();
    do_my_work();
	auto end_time = clk::now();

	auto duration_nn = std::chrono::duration_cast<ms>(end_time - begin_time);
	std::cout << "timecost: " << (double)duration_nn.count() << " ms" << std::endl;
	return 0;
}

0 人点赞