2 * ******************************************************************************
\r
3 * Copyright (C) 2007, International Business Machines Corporation and * others.
\r
4 * All Rights Reserved. *
\r
5 * ******************************************************************************
\r
7 package com.ibm.icu.dev.test.perf;
\r
9 import java.text.ParseException;
\r
10 import java.util.Locale;
\r
15 public class DecimalFormatPerformanceTest extends PerfTest {
\r
18 String decimalAsString;
\r
20 Number decimalAsNumber;
\r
22 com.ibm.icu.text.DecimalFormat[] icuDecimalFormat;
\r
24 java.text.DecimalFormat[] javaDecimalFormat;
\r
26 public static void main(String[] args) throws Exception {
\r
27 new DecimalFormatPerformanceTest().run(args);
\r
30 protected void setup(String[] args) {
\r
32 if (args.length == 0 || args.length > 2) {
\r
33 throw new UsageException();
\r
39 locale = Locale.getDefault();
\r
41 icuDecimalFormat = new com.ibm.icu.text.DecimalFormat[threads];
\r
42 javaDecimalFormat = new java.text.DecimalFormat[threads];
\r
43 for (int i = 0; i < threads; i++) {
\r
44 icuDecimalFormat[i] = new com.ibm.icu.text.DecimalFormat(pattern,
\r
45 new com.ibm.icu.text.DecimalFormatSymbols(locale));
\r
46 javaDecimalFormat[i] = new java.text.DecimalFormat(pattern,
\r
47 new java.text.DecimalFormatSymbols(locale));
\r
50 if (args.length == 2) {
\r
51 decimalAsString = args[1];
\r
52 decimalAsNumber = icuDecimalFormat[0].parse(decimalAsString);
\r
54 } catch (Exception e) {
\r
55 e.printStackTrace();
\r
56 throw new RuntimeException(e.getMessage());
\r
61 PerfTest.Function TestICUConstruction() {
\r
62 return new PerfTest.Function() {
\r
63 public void call() {
\r
64 new com.ibm.icu.text.DecimalFormat(pattern,
\r
65 new com.ibm.icu.text.DecimalFormatSymbols(locale));
\r
70 PerfTest.Function TestJDKConstruction() {
\r
71 return new PerfTest.Function() {
\r
72 public void call() {
\r
73 new java.text.DecimalFormat(pattern, new java.text.DecimalFormatSymbols(locale));
\r
78 PerfTest.Function TestICUParse() {
\r
79 return new PerfTest.Function() {
\r
80 public void call(int id) {
\r
82 icuDecimalFormat[id].parse(decimalAsString);
\r
83 } catch (ParseException e) {
\r
84 e.printStackTrace();
\r
85 throw new RuntimeException(e.getMessage());
\r
91 PerfTest.Function TestJDKParse() {
\r
92 return new PerfTest.Function() {
\r
93 public void call(int id) {
\r
95 javaDecimalFormat[id].parse(decimalAsString);
\r
96 } catch (ParseException e) {
\r
97 e.printStackTrace();
\r
98 throw new RuntimeException(e.getMessage());
\r
104 PerfTest.Function TestICUFormat() {
\r
105 return new PerfTest.Function() {
\r
106 public void call(int id) {
\r
107 icuDecimalFormat[id].format(decimalAsNumber);
\r
112 PerfTest.Function TestJDKFormat() {
\r
113 return new PerfTest.Function() {
\r
114 public void call(int id) {
\r
115 javaDecimalFormat[id].format(decimalAsNumber);
\r