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

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

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/android/jni_android.cc ('k') | base/android/jni_array.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_android.h"
6
7 #include "base/at_exit.h"
8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace base {
12 namespace android {
13
14 namespace {
15
16 base::subtle::AtomicWord g_atomic_id = 0;
17 int LazyMethodIDCall(JNIEnv* env, jclass clazz, int p) {
18 jmethodID id = base::android::MethodID::LazyGet<
19 base::android::MethodID::TYPE_STATIC>(
20 env, clazz,
21 "abs",
22 "(I)I",
23 &g_atomic_id);
24
25 return env->CallStaticIntMethod(clazz, id, p);
26 }
27
28 int MethodIDCall(JNIEnv* env, jclass clazz, jmethodID id, int p) {
29 return env->CallStaticIntMethod(clazz, id, p);
30 }
31
32 } // namespace
33
34 TEST(JNIAndroidMicrobenchmark, MethodId) {
35 JNIEnv* env = AttachCurrentThread();
36 ScopedJavaLocalRef<jclass> clazz(GetClass(env, "java/lang/Math"));
37 base::Time start_lazy = base::Time::Now();
38 int o = 0;
39 for (int i = 0; i < 1024; ++i)
40 o += LazyMethodIDCall(env, clazz.obj(), i);
41 base::Time end_lazy = base::Time::Now();
42
43 jmethodID id = reinterpret_cast<jmethodID>(g_atomic_id);
44 base::Time start = base::Time::Now();
45 for (int i = 0; i < 1024; ++i)
46 o += MethodIDCall(env, clazz.obj(), id, i);
47 base::Time end = base::Time::Now();
48
49 // On a Galaxy Nexus, results were in the range of:
50 // JNI LazyMethodIDCall (us) 1984
51 // JNI MethodIDCall (us) 1861
52 LOG(ERROR) << "JNI LazyMethodIDCall (us) " <<
53 base::TimeDelta(end_lazy - start_lazy).InMicroseconds();
54 LOG(ERROR) << "JNI MethodIDCall (us) " <<
55 base::TimeDelta(end - start).InMicroseconds();
56 LOG(ERROR) << "JNI " << o;
57 }
58
59
60 } // namespace android
61 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_android.cc ('k') | base/android/jni_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698