1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package benchmarks.regression; 18 19 import java.util.Locale; 20 import java.util.TimeZone; 21 22 import static libcore.icu.DateUtilsBridge.FORMAT_ABBREV_RELATIVE; 23 import static libcore.icu.RelativeDateTimeFormatter.getRelativeDateTimeString; 24 import static libcore.icu.RelativeDateTimeFormatter.getRelativeTimeSpanString; 25 26 public class RelativeDateTimeFormatterBenchmark { 27 public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString(int reps) throws Exception { 28 Locale l = Locale.US; 29 TimeZone utc = TimeZone.getTimeZone("Europe/London"); 30 int flags = 0; 31 32 for (int rep = 0; rep < reps; ++rep) { 33 getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags); 34 } 35 } 36 37 public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV(int reps) throws Exception { 38 Locale l = Locale.US; 39 TimeZone utc = TimeZone.getTimeZone("UTC"); 40 int flags = FORMAT_ABBREV_RELATIVE; 41 42 for (int rep = 0; rep < reps; ++rep) { 43 getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags); 44 } 45 } 46 47 public void timeRelativeDateTimeFormatter_getRelativeDateTimeString(int reps) throws Exception { 48 Locale l = Locale.US; 49 TimeZone utc = TimeZone.getTimeZone("UTC"); 50 int flags = 0; 51 52 for (int rep = 0; rep < reps; ++rep) { 53 getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags); 54 } 55 } 56 57 public void timeRelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV(int reps) throws Exception { 58 Locale l = Locale.US; 59 TimeZone utc = TimeZone.getTimeZone("America/Los_Angeles"); 60 int flags = FORMAT_ABBREV_RELATIVE; 61 62 for (int rep = 0; rep < reps; ++rep) { 63 getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags); 64 } 65 } 66 } 67