Add benchmark for jobject functions
Measures performance of:
Add/RemoveLocalRef
Add/RemoveGlobalRef
Add/RemoveWeakGlobalRef
Decoding local, weak, global, handle scope jobjects.
N5 results:
benchmark ns linear runtime
AddRemoveGlobal 476.7 ===========================
AddRemoveLocal 42.0 ==
AddRemoveWeakGlobal 519.7 ==============================
DecodeGlobal 69.9 ====
DecodeHandleScopeRef 38.9 ==
DecodeLocal 70.7 ====
DecodeWeakGlobal 119.7 ======
Change-Id: Iba014a9993909ee45fd52ae48d6dea8428a86bf2
diff --git a/benchmark/jobject-benchmark/src/JObjectBenchmark.java b/benchmark/jobject-benchmark/src/JObjectBenchmark.java
new file mode 100644
index 0000000..f4c059c
--- /dev/null
+++ b/benchmark/jobject-benchmark/src/JObjectBenchmark.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.google.caliper.SimpleBenchmark;
+
+public class JObjectBenchmark extends SimpleBenchmark {
+ public JObjectBenchmark() {
+ // Make sure to link methods before benchmark starts.
+ System.loadLibrary("artbenchmark");
+ timeAddRemoveLocal(1);
+ timeDecodeLocal(1);
+ timeAddRemoveGlobal(1);
+ timeDecodeGlobal(1);
+ timeAddRemoveWeakGlobal(1);
+ timeDecodeWeakGlobal(1);
+ timeDecodeHandleScopeRef(1);
+ }
+
+ public native void timeAddRemoveLocal(int reps);
+ public native void timeDecodeLocal(int reps);
+ public native void timeAddRemoveGlobal(int reps);
+ public native void timeDecodeGlobal(int reps);
+ public native void timeAddRemoveWeakGlobal(int reps);
+ public native void timeDecodeWeakGlobal(int reps);
+ public native void timeDecodeHandleScopeRef(int reps);
+}