]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/perf/DecimalFormatPerformanceTest.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / perf / DecimalFormatPerformanceTest.java
1 /*\r
2  * ******************************************************************************\r
3  * Copyright (C) 2007, International Business Machines Corporation and * others.\r
4  * All Rights Reserved. *\r
5  * ******************************************************************************\r
6  */\r
7 package com.ibm.icu.dev.test.perf;\r
8 \r
9 import java.text.ParseException;\r
10 import java.util.Locale;\r
11 \r
12 /**\r
13  * @author ajmacher\r
14  */\r
15 public class DecimalFormatPerformanceTest extends PerfTest {\r
16     String pattern;\r
17 \r
18     String decimalAsString;\r
19 \r
20     Number decimalAsNumber;\r
21 \r
22     com.ibm.icu.text.DecimalFormat[] icuDecimalFormat;\r
23 \r
24     java.text.DecimalFormat[] javaDecimalFormat;\r
25 \r
26     public static void main(String[] args) throws Exception {\r
27         new DecimalFormatPerformanceTest().run(args);\r
28     }\r
29 \r
30     protected void setup(String[] args) {\r
31         try {\r
32             if (args.length == 0 || args.length > 2) {\r
33                 throw new UsageException();\r
34             }\r
35 \r
36             pattern = args[0];\r
37 \r
38             if (locale == null)\r
39                 locale = Locale.getDefault();\r
40 \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
48             }\r
49 \r
50             if (args.length == 2) {\r
51                 decimalAsString = args[1];\r
52                 decimalAsNumber = icuDecimalFormat[0].parse(decimalAsString);\r
53             }\r
54         } catch (Exception e) {\r
55             e.printStackTrace();\r
56             throw new RuntimeException(e.getMessage());\r
57         }\r
58 \r
59     }\r
60 \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
66             }\r
67         };\r
68     }\r
69 \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
74             }\r
75         };\r
76     }\r
77 \r
78     PerfTest.Function TestICUParse() {\r
79         return new PerfTest.Function() {\r
80             public void call(int id) {\r
81                 try {\r
82                     icuDecimalFormat[id].parse(decimalAsString);\r
83                 } catch (ParseException e) {\r
84                     e.printStackTrace();\r
85                     throw new RuntimeException(e.getMessage());\r
86                 }\r
87             }\r
88         };\r
89     }\r
90 \r
91     PerfTest.Function TestJDKParse() {\r
92         return new PerfTest.Function() {\r
93             public void call(int id) {\r
94                 try {\r
95                     javaDecimalFormat[id].parse(decimalAsString);\r
96                 } catch (ParseException e) {\r
97                     e.printStackTrace();\r
98                     throw new RuntimeException(e.getMessage());\r
99                 }\r
100             }\r
101         };\r
102     }\r
103 \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
108             }\r
109         };\r
110     }\r
111 \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
116             }\r
117         };\r
118     }\r
119 }\r