diff options
author | Elliott Hughes <enh@google.com> | 2013-09-11 14:42:56 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-09-11 14:45:31 -0700 |
commit | fd1d5e92b2eaf785cb18aa295b7b846cfc5e29af (patch) | |
tree | 8267529944f2f82af3f2d2d8cbb6652b5a91585b /benchmarks/src | |
parent | 298a19b176fafcebd47dd820adee37f1039ea6e3 (diff) | |
download | libcore-fd1d5e92b2eaf785cb18aa295b7b846cfc5e29af.zip libcore-fd1d5e92b2eaf785cb18aa295b7b846cfc5e29af.tar.gz libcore-fd1d5e92b2eaf785cb18aa295b7b846cfc5e29af.tar.bz2 |
icu4c DateIntervalFormat objects are expensive enough that we need to cache them.
It takes ~1ms to create a DateIntervalFormat on a z620, and around 8ms on a
current mobile device (Nexus 4). Add a small cache of recently-used formatters,
using a big lock rather than per-thread caches since this typically only
happens on the UI thread anyway, and because all the other frameworks date/time
formatting is behind a single lock too.
Bug: 10696944
Change-Id: I8ccbe0b31b722a95a08fbc5a119173b7a0f44807
Diffstat (limited to 'benchmarks/src')
-rw-r--r-- | benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java new file mode 100644 index 0000000..02d8f97 --- /dev/null +++ b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 Google Inc. + * + * 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.DateIntervalFormat.*; + +public class DateIntervalFormatBenchmark extends SimpleBenchmark { + public void timeDateIntervalFormat_formatDateRange_DATE(int reps) throws Exception { + Locale l = Locale.US; + TimeZone utc = TimeZone.getTimeZone("UTC"); + int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY; + + for (int rep = 0; rep < reps; ++rep) { + formatDateRange(l, utc, 0L, 0L, flags); + } + } + + public void timeDateIntervalFormat_formatDateRange_TIME(int reps) throws Exception { + Locale l = Locale.US; + TimeZone utc = TimeZone.getTimeZone("UTC"); + int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR; + + for (int rep = 0; rep < reps; ++rep) { + formatDateRange(l, utc, 0L, 0L, flags); + } + } + + public void timeDateIntervalFormat_formatDateRange_DATE_TIME(int reps) throws Exception { + Locale l = Locale.US; + TimeZone utc = TimeZone.getTimeZone("UTC"); + int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_TIME | FORMAT_24HOUR; + + for (int rep = 0; rep < reps; ++rep) { + formatDateRange(l, utc, 0L, 0L, flags); + } + } +} |