美文网首页
各种语言统计方法耗时

各种语言统计方法耗时

作者: GeorgeMR | 来源:发表于2018-10-15 22:00 被阅读0次

Java

long startTime = System.currentTimeMillis();

// 要统计的运行代码
...

// 单位为 ms    
long duration = System.currentTimeMillis() - startTime;

C/C++

clock()

// 首先引入头文件
#include "time.h"

clock_t start = clock();

//要统计的运行代码
...
    
double duration = (double) (clock() - start);

GetTickCount()

// 首先引入头文件
#include "winbase.h"

long startTime = GetTickCount();

//要统计的运行代码
...
 
// 单位为 ms    
long duration = GetTickCount() - startTime;

object-c

double startTime = [[NSDate data] timeIntervalSince1970]*1000;

// 要统计的运行代码
...
   
// 单位为 ms    
double duration = [[NSDate data] timeIntervalSince1970]*1000 - startTime;

相关文章

网友评论

      本文标题:各种语言统计方法耗时

      本文链接:https://www.haomeiwen.com/subject/jjiqzftx.html