summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-02-06 15:03:01 -0800
committerTao Bao <tbao@google.com>2015-02-11 10:22:32 -0800
commit7bcff480531c1aa18de118c6f36dd397d5e1ad86 (patch)
tree669efcffdeaf3df1873c9672f2f6fa62ffc625c1 /benchmarks
parenta9c24ad83f3cd18738268559169ba901b5f70232 (diff)
downloadlibcore-7bcff480531c1aa18de118c6f36dd397d5e1ad86.zip
libcore-7bcff480531c1aa18de118c6f36dd397d5e1ad86.tar.gz
libcore-7bcff480531c1aa18de118c6f36dd397d5e1ad86.tar.bz2
Use ICU for relative time formatting
Rewrite the DateUtils' relative time formatting APIs (getRelativeTimeSpanString, getRelativeDateTimeString) to use ICU ones. Two APIs that take withPreposition parameter are not changed. Because (a) ICU doesn't provide functionality to format preposition; (b) They are not really computing relative time but instead calling formatDateRange() to get the absolute time/date string. Benchmark results on aosp_hammerhead-userdebug: before: benchmark us linear runtime DateUtils_getRelativeDateTimeString 127.1 ========================== DateUtils_getRelativeDateTimeString_ABBREV 145.0 ============================== DateUtils_getRelativeTimeSpanString 28.0 ===== DateUtils_getRelativeTimeSpanString_ABBREV 27.9 ===== now: benchmark us linear runtime RelativeDateTimeFormatter_getRelativeDateTimeString 119.2 ========================== RelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV 133.8 ============================== RelativeDateTimeFormatter_getRelativeTimeSpanString 24.6 ===== RelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV 24.7 ===== Bug: 19146457 Bug: 5252772 Change-Id: Ief74608354964a17e42191d7b1a58964f3a9acfd
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java b/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java
new file mode 100644
index 0000000..30670b4
--- /dev/null
+++ b/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package benchmarks.regression;
+
+import com.google.caliper.SimpleBenchmark;
+
+import java.util.Locale;
+import java.util.TimeZone;
+
+import static libcore.icu.RelativeDateTimeFormatter.getRelativeDateTimeString;
+import static libcore.icu.RelativeDateTimeFormatter.getRelativeTimeSpanString;
+import static libcore.icu.RelativeDateTimeFormatter.FORMAT_ABBREV_RELATIVE;
+
+public class RelativeDateTimeFormatterBenchmark extends SimpleBenchmark {
+ public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString(int reps) throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("Europe/London");
+ int flags = 0;
+
+ for (int rep = 0; rep < reps; ++rep) {
+ getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags);
+ }
+ }
+
+ public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV(int reps) throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+ int flags = FORMAT_ABBREV_RELATIVE;
+
+ for (int rep = 0; rep < reps; ++rep) {
+ getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags);
+ }
+ }
+
+ public void timeRelativeDateTimeFormatter_getRelativeDateTimeString(int reps) throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+ int flags = 0;
+
+ for (int rep = 0; rep < reps; ++rep) {
+ getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags);
+ }
+ }
+
+ public void timeRelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV(int reps) throws Exception {
+ Locale l = Locale.US;
+ TimeZone utc = TimeZone.getTimeZone("America/Los_Angeles");
+ int flags = FORMAT_ABBREV_RELATIVE;
+
+ for (int rep = 0; rep < reps; ++rep) {
+ getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags);
+ }
+ }
+}