java端:java
以毫秒为单位 long startTime = System.currentTimeMillis(); // 获取开始时间 // doThing(); // 测试的代码段 long endTime = System.currentTimeMillis(); // 获取结束时间 Log.e("wsy","代码运行时间: " + (endTime - startTime) + "ms"); 1 2 3 4 以纳秒为单位 long startTime = System.nanoTime(); // 获取开始时间 // doThing(); // 测试的代码段 long endTime = System.nanoTime(); // 获取结束时间 Log.e("wsy","代码运行时间: " + (endTime - startTime) + "ms");
jni,好像打印不出来,须要log.e测试
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "caltime_Jni.h" JNIEXPORT jlong JNICALL Java_caltime_Jni_calculateTime (JNIEnv *e, jobject jo){ long start, end; int i,j,k; long a; //start time start = clock(); //do something for (i = 0; i < 14400000; i++) { a = 255.0 / 16.0; } //end time end = clock(); return end - start; } JNIEXPORT jstring JNICALL Java_caltime_Jni_printStr (JNIEnv *e, jobject j) { return (*e)->NewStringUTF(e, "Rambow"); }