Index: base/android/jni_android_unittest.cc |
diff --git a/base/android/jni_android_unittest.cc b/base/android/jni_android_unittest.cc |
index abecad778b47c72830d1e0a3345f6cf7c1d05140..65b5265ed66bed668559a34ecfc490852981bf0f 100644 |
--- a/base/android/jni_android_unittest.cc |
+++ b/base/android/jni_android_unittest.cc |
@@ -33,6 +33,24 @@ jmethodID GetMethodIDWrapper(JNIEnv* env, jclass clazz, const char* method, |
return g_last_method_id; |
} |
+ |
joth
2012/10/02 17:47:43
\n nit
bulach
2012/10/03 13:09:00
Done.
|
+static jmethodID g_method_id = 0; |
joth
2012/10/02 17:47:43
this should be declared as an AtomicWord
nit: sta
bulach
2012/10/03 13:09:00
Done.
|
+int LazyMethodIDCall(JNIEnv* env, jclass clazz, int p) { |
+ base::android::LazyMethodID::Get< |
+ base::android::LazyMethodID::METHODTYPE_STATIC, |
+ base::android::LazyMethodID::EXCEPTIONCHECK_NO>( |
+ env, clazz, |
+ "abs", |
+ "(I)I", |
+ &g_method_id); |
joth
2012/10/02 17:47:43
are you specifically using a global method id rath
bulach
2012/10/03 13:09:00
yes. I'm trying to reproduce as much as possible t
|
+ |
+ return env->CallStaticIntMethod(clazz, g_method_id, p); |
+} |
+ |
+int MethodIDCall(JNIEnv* env, jclass clazz, int p) { |
+ return env->CallStaticIntMethod(clazz, g_method_id, p); |
+} |
joth
2012/10/02 17:47:43
AIUI it's preferred to put single-use anon methods
bulach
2012/10/03 13:09:00
moved to its own file..
|
+ |
} // namespace |
class JNIAndroidTest : public testing::Test { |
@@ -90,5 +108,26 @@ TEST_F(JNIAndroidTest, GetMethodIDFromClassNameCaching) { |
EXPECT_EQ(g_last_method_id, id3); |
} |
+TEST(JNIAndroidMicrobenchmark, MethodId) { |
joth
2012/10/02 17:47:43
in net/ they put micro benchmarks into a different
bulach
2012/10/03 13:09:00
yeah, the extra target doesn't seem to be worth th
|
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jclass> clazz(GetClass(env, "java/lang/Math")); |
+ base::Time start_lazy = base::Time::Now(); |
+ int o = 0; |
+ for (int i = 0; i < 1024; ++i) |
+ o += LazyMethodIDCall(env, clazz.obj(), i); |
+ base::Time end_lazy = base::Time::Now(); |
+ |
+ base::Time start = base::Time::Now(); |
+ for (int i = 0; i < 1024; ++i) |
+ o += MethodIDCall(env, clazz.obj(), i); |
+ base::Time end = base::Time::Now(); |
+ |
+ LOG(ERROR) << "JNI LazyMethodIDCall (us) " << |
+ base::TimeDelta(end_lazy - start_lazy).InMicroseconds(); |
+ LOG(ERROR) << "JNI MethodIDCall (us) " << |
+ base::TimeDelta(end - start).InMicroseconds(); |
+ LOG(ERROR) << "JNI " << o; |
joth
2012/10/02 17:47:43
can you include in comment here as to typical resu
bulach
2012/10/03 13:09:00
good point! done
|
+} |
+ |
} // namespace android |
} // namespace base |