From 12fbbc16959d078dde23b3b15c8d3d127ef33507 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 15 Apr 2015 16:40:51 +0100 Subject: Use ICU4J more in DateIntervalFormat and RelativeDateTimeFormatter General strategy: Switch to ICU classes for Calendar, and generally use ICU classes earlier to avoid multiple creations. This also incorporates some feedback from narayan@ from https://android-review.googlesource.com/#/c/145662/ Some small optimizations applied but the goal was not to make it much faster, just to confirm it wasn't much slower. It has sped up some methods, and slowed down others, but not much difference in absolute terms. All times in microseconds measured on a mako. Original: RelativeDateTimeFormatter_getRelativeDateTimeString 582.4 RelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV 603.2 RelativeDateTimeFormatter_getRelativeTimeSpanString 39.9 RelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV 39.1 After: RelativeDateTimeFormatter_getRelativeDateTimeString 207.2 RelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV 218.2 RelativeDateTimeFormatter_getRelativeTimeSpanString 70.5 RelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV 67.4 Original: DateIntervalFormat_formatDateRange_DATE 290 DateIntervalFormat_formatDateRange_DATE_TIME 298 DateIntervalFormat_formatDateRange_TIME 276 After: DateIntervalFormat_formatDateRange_DATE 244 DateIntervalFormat_formatDateRange_DATE_TIME 256 DateIntervalFormat_formatDateRange_TIME 208 Change-Id: If043bd55ffec37ed2735aa1593f327b38749218c --- .../src/benchmarks/regression/DateIntervalFormatBenchmark.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java index 02d8f97..e84c287 100644 --- a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java +++ b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java @@ -18,14 +18,14 @@ package benchmarks.regression; import com.google.caliper.SimpleBenchmark; -import java.util.Locale; -import java.util.TimeZone; +import android.icu.util.ULocale; +import android.icu.util.TimeZone; import static libcore.icu.DateIntervalFormat.*; public class DateIntervalFormatBenchmark extends SimpleBenchmark { public void timeDateIntervalFormat_formatDateRange_DATE(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY; @@ -35,7 +35,7 @@ public class DateIntervalFormatBenchmark extends SimpleBenchmark { } public void timeDateIntervalFormat_formatDateRange_TIME(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR; @@ -45,7 +45,7 @@ public class DateIntervalFormatBenchmark extends SimpleBenchmark { } public void timeDateIntervalFormat_formatDateRange_DATE_TIME(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_TIME | FORMAT_24HOUR; -- cgit v1.1