[iuud8]cocos2dx编程中获得代码段执行时间,精确到毫秒级
2015-01-04 11:20
225 查看
在程序书写过程中,我们常常需要得到某一段代码的执行时间,来判断当前代码是否冗余,是否会消耗大量的系统资源,或者在资源加载的过程中,判断是那些资源消耗了大量的时间。
在c++中,有一个活的时间的办法,但精度只到秒:
struct timeval now;
struct tm* time;
gettimeofday(&now, NULL);
time = localtime(&now.tv_sec);
char date[32] = {0};
sprintf(date, "%d%02d%02d",time->tm_year + 1900, time->tm_mon + 1, time->tm_mday);
如果想要获取到毫秒级时间差,则
auto t1 = std::chrono::high_resolution_clock::now();
{
......
}
auto t2 = std::chrono::high_resolution_clock::now();
log(">>>>>>>>>>>time1 = %lld", std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count());
中间{ ...... }表示你要获取执行时间的代码段,最后输出时间即为该代码段的时间
在c++中,有一个活的时间的办法,但精度只到秒:
struct timeval now;
struct tm* time;
gettimeofday(&now, NULL);
time = localtime(&now.tv_sec);
char date[32] = {0};
sprintf(date, "%d%02d%02d",time->tm_year + 1900, time->tm_mon + 1, time->tm_mday);
如果想要获取到毫秒级时间差,则
auto t1 = std::chrono::high_resolution_clock::now();
{
......
}
auto t2 = std::chrono::high_resolution_clock::now();
log(">>>>>>>>>>>time1 = %lld", std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count());
中间{ ...... }表示你要获取执行时间的代码段,最后输出时间即为该代码段的时间
相关文章推荐
- 获得在查询分析器里执行程序的精确时间以及查询效率问题
- C#获得方法执行的精确时间
- C#获得方法执行的精确时间
- 在Linux下获得毫秒级的精确时间
- 计算C++程序执行时间 精确到毫秒级
- 测试代码段的执行时间并精确到微秒
- 精确计算代码段执行时间
- VC精确计算代码执行时间
- c#中精确计算程序执行时间
- SQLserver不是可以识别的内置函数名称"的错误,通过set statistics time on能得到SQL语句的执行时间精确到毫秒.
- 获得sql 语句执行时间
- Java精确测量代码运行时间 代码执行时间 纳秒 nanoTime
- 如何得到SQL精确的执行时间
- 如何得到精确的SQL执行时间
- 获得T-SQL 执行计划和IO,CPU运行时间
- 在vc++里获得精确的花费时间
- 精确计算代码执行时间
- 获得当天的时间范围(精确到毫秒)
- 如何在asp.net中获得页面执行所耗时间?
- 获得毫秒级的流逝时间, 测试代码效率时很有用