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;