Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: base/android/jni_method_id_unittest.cc

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split files Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/android/jni_method_id.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "base/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace base {
13 namespace android {
14
15 namespace {
16
17 base::subtle::AtomicWord g_atomic_id = 0;
18 int LazyMethodIDCall(JNIEnv* env, jclass clazz, int p) {
19 jmethodID id = base::android::MethodID::LazyGet<
20 base::android::MethodID::METHODTYPE_STATIC,
21 base::android::MethodID::EXCEPTIONCHECK_NO>(
22 env, clazz,
23 "abs",
24 "(I)I",
25 &g_atomic_id);
26
27 return env->CallStaticIntMethod(clazz, id, p);
28 }
29
30 int MethodIDCall(JNIEnv* env, jclass clazz, jmethodID id, int p) {
31 return env->CallStaticIntMethod(clazz, id, p);
32 }
33
34 } // namespace
35
36 TEST(JNIAndroidMicrobenchmark, MethodId) {
37 JNIEnv* env = AttachCurrentThread();
38 ScopedJavaLocalRef<jclass> clazz(GetClass(env, "java/lang/Math"));
39 base::Time start_lazy = base::Time::Now();
40 int o = 0;
41 for (int i = 0; i < 1024; ++i)
42 o += LazyMethodIDCall(env, clazz.obj(), i);
joth 2012/10/03 17:31:52 depending on your goals, this test is skewed again
43 base::Time end_lazy = base::Time::Now();
44
45 jmethodID id = reinterpret_cast<jmethodID>(g_atomic_id);
46 base::Time start = base::Time::Now();
47 for (int i = 0; i < 1024; ++i)
48 o += MethodIDCall(env, clazz.obj(), id, i);
49 base::Time end = base::Time::Now();
50
51 // On a Galaxy Nexus, results were in the range of:
52 // JNI LazyMethodIDCall (us) 1984
53 // JNI MethodIDCall (us) 1861
54 LOG(ERROR) << "JNI LazyMethodIDCall (us) " <<
55 base::TimeDelta(end_lazy - start_lazy).InMicroseconds();
56 LOG(ERROR) << "JNI MethodIDCall (us) " <<
57 base::TimeDelta(end - start).InMicroseconds();
58 LOG(ERROR) << "JNI " << o;
59 }
60
61 } // namespace android
62 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698