001: /*
002: **********************************************************************
003: * Copyright (c) 2002-2004, International Business Machines
004: * Corporation and others. All Rights Reserved.
005: **********************************************************************
006: */
007: package com.ibm.icu.dev.test.perf;
008:
009: import com.ibm.icu.text.*;
010:
011: public class NormalizerPerformanceTest extends PerfTest {
012:
013: String[] NFDFileLines;
014: String[] NFCFileLines;
015: String[] fileLines;
016:
017: public static void main(String[] args) throws Exception {
018: new NormalizerPerformanceTest().run(args);
019: }
020:
021: protected void setup(String[] args) {
022: if (bulk_mode == line_mode) {
023: printUsage();
024: }
025: if (fileName.equalsIgnoreCase("")) {
026: printUsage();
027: }
028: fileLines = readLines(fileName, encoding, bulk_mode);
029: NFDFileLines = normalizeInput(fileLines, Normalizer.NFD);
030: NFCFileLines = normalizeInput(fileLines, Normalizer.NFC);
031: }
032:
033: // Test NFC Performance
034: PerfTest.Function TestICU_NFC_NFD_Text() {
035: return new PerfTest.Function() {
036: public void call() {
037: for (int i = 0; i < NFDFileLines.length; i++) {
038: Normalizer.normalize(NFDFileLines[i],
039: Normalizer.NFC);
040: }
041: }
042:
043: public long getOperationsPerIteration() {
044: int totalChars = 0;
045: for (int i = 0; i < NFDFileLines.length; i++) {
046: totalChars = totalChars + NFDFileLines[i].length();
047: }
048: return totalChars;
049: }
050: };
051: }
052:
053: PerfTest.Function TestICU_NFC_NFC_Text() {
054: return new PerfTest.Function() {
055: public void call() {
056: for (int i = 0; i < NFCFileLines.length; i++) {
057: Normalizer.normalize(NFCFileLines[i],
058: Normalizer.NFC);
059: }
060: }
061:
062: public long getOperationsPerIteration() {
063: int totalChars = 0;
064: for (int i = 0; i < NFCFileLines.length; i++) {
065: totalChars = totalChars + NFCFileLines[i].length();
066: }
067: return totalChars;
068: }
069: };
070: }
071:
072: PerfTest.Function TestICU_NFC_Orig_Text() {
073: return new PerfTest.Function() {
074: public void call() {
075: for (int i = 0; i < fileLines.length; i++) {
076: Normalizer.normalize(fileLines[i], Normalizer.NFC);
077: }
078: }
079:
080: public long getOperationsPerIteration() {
081: int totalChars = 0;
082: for (int i = 0; i < fileLines.length; i++) {
083: totalChars = totalChars + fileLines[i].length();
084: }
085: return totalChars;
086: }
087: };
088: }
089:
090: // Test NFD Performance
091: PerfTest.Function TestICU_NFD_NFD_Text() {
092: return new PerfTest.Function() {
093: public void call() {
094: for (int i = 0; i < NFDFileLines.length; i++) {
095: Normalizer.normalize(NFDFileLines[i],
096: Normalizer.NFD);
097: }
098: }
099:
100: public long getOperationsPerIteration() {
101: int totalChars = 0;
102: for (int i = 0; i < NFDFileLines.length; i++) {
103: totalChars = totalChars + NFDFileLines[i].length();
104: }
105: return totalChars;
106: }
107: };
108: }
109:
110: PerfTest.Function TestICU_NFD_NFC_Text() {
111: return new PerfTest.Function() {
112: public void call() {
113: for (int i = 0; i < NFCFileLines.length; i++) {
114: Normalizer.normalize(NFCFileLines[i],
115: Normalizer.NFD);
116: }
117: }
118:
119: public long getOperationsPerIteration() {
120: int totalChars = 0;
121: for (int i = 0; i < NFCFileLines.length; i++) {
122: totalChars = totalChars + NFCFileLines[i].length();
123: }
124: return totalChars;
125: }
126: };
127: }
128:
129: PerfTest.Function TestICU_NFD_Orig_Text() {
130: return new PerfTest.Function() {
131: public void call() {
132: for (int i = 0; i < fileLines.length; i++) {
133: Normalizer.normalize(fileLines[i], Normalizer.NFD);
134: }
135: }
136:
137: public long getOperationsPerIteration() {
138: int totalChars = 0;
139: for (int i = 0; i < fileLines.length; i++) {
140: totalChars = totalChars + fileLines[i].length();
141: }
142: return totalChars;
143: }
144: };
145: }
146:
147: /** I really wish there was conditional compilation in Java
148: // Test NFC Performance
149: PerfTest.Function TestJDK_NFC_NFD_Text() {
150: return new PerfTest.Function() {
151: public void call() {
152: for (int i = 0; i < NFDFileLines.length; i++) {
153: String nfc = sun.text.Normalizer.normalize(NFDFileLines[i], sun.text.Normalizer.COMPOSE,0);
154: }
155: }
156:
157: public long getOperationsPerIteration() {
158: int totalChars = 0;
159: for (int i = 0; i < NFDFileLines.length; i++) {
160: totalChars = totalChars + NFDFileLines[i].length();
161: }
162: return totalChars;
163: }
164: };
165: }
166:
167: PerfTest.Function TestJDK_NFC_NFC_Text() {
168: return new PerfTest.Function() {
169: public void call() {
170: for (int i = 0; i < NFCFileLines.length; i++) {
171: String nfc = sun.text.Normalizer.normalize(NFCFileLines[i], sun.text.Normalizer.COMPOSE,0);
172: }
173: }
174:
175: public long getOperationsPerIteration() {
176: int totalChars = 0;
177: for (int i = 0; i < NFCFileLines.length; i++) {
178: totalChars = totalChars + NFCFileLines[i].length();
179: }
180: return totalChars;
181: }
182: };
183: }
184:
185: PerfTest.Function TestJDK_NFC_Orig_Text() {
186: return new PerfTest.Function() {
187: public void call() {
188: for (int i = 0; i < fileLines.length; i++) {
189: String nfc = sun.text.Normalizer.normalize(fileLines[i], sun.text.Normalizer.COMPOSE,0);
190: }
191: }
192:
193: public long getOperationsPerIteration() {
194: int totalChars = 0;
195: for (int i = 0; i < fileLines.length; i++) {
196: totalChars = totalChars + fileLines[i].length();
197: }
198: return totalChars;
199: }
200: };
201: }
202:
203: // Test NFD Performance
204: PerfTest.Function TestJDK_NFD_NFD_Text() {
205: return new PerfTest.Function() {
206: public void call() {
207: for (int i = 0; i < NFDFileLines.length; i++) {
208: String nfc = sun.text.Normalizer.normalize(NFDFileLines[i], sun.text.Normalizer.DECOMP,0);
209: }
210: }
211:
212: public long getOperationsPerIteration() {
213: int totalChars = 0;
214: for (int i = 0; i < NFDFileLines.length; i++) {
215: totalChars = totalChars + NFDFileLines[i].length();
216: }
217: return totalChars;
218: }
219: };
220: }
221:
222: PerfTest.Function TestJDK_NFD_NFC_Text() {
223: return new PerfTest.Function() {
224: public void call() {
225: for (int i = 0; i < NFCFileLines.length; i++) {
226: String nfc = sun.text.Normalizer.normalize(NFCFileLines[i], sun.text.Normalizer.DECOMP,0);
227: }
228: }
229:
230: public long getOperationsPerIteration() {
231: int totalChars = 0;
232: for (int i = 0; i < NFCFileLines.length; i++) {
233: totalChars = totalChars + NFCFileLines[i].length();
234: }
235: return totalChars;
236: }
237: };
238: }
239:
240: PerfTest.Function TestJDK_NFD_Orig_Text() {
241: return new PerfTest.Function() {
242: public void call() {
243: for (int i = 0; i < fileLines.length; i++) {
244: String nfc = sun.text.Normalizer.normalize(fileLines[i], sun.text.Normalizer.DECOMP,0);
245: }
246: }
247:
248: public long getOperationsPerIteration() {
249: int totalChars = 0;
250: for (int i = 0; i < fileLines.length; i++) {
251: totalChars = totalChars + fileLines[i].length();
252: }
253: return totalChars;
254: }
255: };
256: }
257: // Test FCD Performance
258: PerfTest.Function TestICU_FCD_NFD_Text() {
259: return new PerfTest.Function() {
260: public void call() {
261: for (int i = 0; i < NFDFileLines.length; i++) {
262: String nfc = Normalizer.normalize(NFDFileLines[i], Normalizer.FCD);
263: }
264: }
265:
266: public long getOperationsPerIteration() {
267: int totalChars = 0;
268: for (int i = 0; i < NFDFileLines.length; i++) {
269: totalChars = totalChars + NFDFileLines[i].length();
270: }
271: return totalChars;
272: }
273: };
274: }
275: **/
276: PerfTest.Function TestICU_FCD_NFC_Text() {
277: return new PerfTest.Function() {
278: public void call() {
279: for (int i = 0; i < NFCFileLines.length; i++) {
280: Normalizer.normalize(NFCFileLines[i],
281: Normalizer.FCD);
282: }
283: }
284:
285: public long getOperationsPerIteration() {
286: int totalChars = 0;
287: for (int i = 0; i < NFCFileLines.length; i++) {
288: totalChars = totalChars + NFCFileLines[i].length();
289: }
290: return totalChars;
291: }
292: };
293: }
294:
295: PerfTest.Function TestICU_FCD_Orig_Text() {
296: return new PerfTest.Function() {
297: public void call() {
298: for (int i = 0; i < fileLines.length; i++) {
299: Normalizer.normalize(fileLines[i], Normalizer.FCD);
300: }
301: }
302:
303: public long getOperationsPerIteration() {
304: int totalChars = 0;
305: for (int i = 0; i < fileLines.length; i++) {
306: totalChars = totalChars + fileLines[i].length();
307: }
308: return totalChars;
309: }
310: };
311: }
312:
313: // Test Quick Check Performance
314: PerfTest.Function TestQC_NFC_NFD_Text() {
315: return new PerfTest.Function() {
316: public void call() {
317: for (int i = 0; i < NFDFileLines.length; i++) {
318: Normalizer.quickCheck(NFDFileLines[i],
319: Normalizer.NFC, 0);
320: }
321: }
322:
323: public long getOperationsPerIteration() {
324: int totalChars = 0;
325: for (int i = 0; i < NFDFileLines.length; i++) {
326: totalChars = totalChars + NFDFileLines[i].length();
327: }
328: return totalChars;
329: }
330: };
331: }
332:
333: PerfTest.Function TestQC_NFC_NFC_Text() {
334: return new PerfTest.Function() {
335: public void call() {
336: for (int i = 0; i < NFCFileLines.length; i++) {
337: Normalizer.quickCheck(NFCFileLines[i],
338: Normalizer.NFC, 0);
339: }
340: }
341:
342: public long getOperationsPerIteration() {
343: int totalChars = 0;
344: for (int i = 0; i < NFCFileLines.length; i++) {
345: totalChars = totalChars + NFCFileLines[i].length();
346: }
347: return totalChars;
348: }
349: };
350: }
351:
352: PerfTest.Function TestQC_NFC_Orig_Text() {
353: return new PerfTest.Function() {
354: public void call() {
355: for (int i = 0; i < fileLines.length; i++) {
356: Normalizer.quickCheck(fileLines[i], Normalizer.NFC,
357: 0);
358: }
359: }
360:
361: public long getOperationsPerIteration() {
362: int totalChars = 0;
363: for (int i = 0; i < fileLines.length; i++) {
364: totalChars = totalChars + fileLines[i].length();
365: }
366: return totalChars;
367: }
368: };
369: }
370:
371: PerfTest.Function TestQC_NFD_NFD_Text() {
372: return new PerfTest.Function() {
373: public void call() {
374: for (int i = 0; i < NFDFileLines.length; i++) {
375: Normalizer.quickCheck(NFDFileLines[i],
376: Normalizer.NFD, 0);
377: }
378: }
379:
380: public long getOperationsPerIteration() {
381: int totalChars = 0;
382: for (int i = 0; i < NFDFileLines.length; i++) {
383: totalChars = totalChars + NFDFileLines[i].length();
384: }
385: return totalChars;
386: }
387: };
388: }
389:
390: PerfTest.Function TestQC_NFD_NFC_Text() {
391: return new PerfTest.Function() {
392: public void call() {
393: for (int i = 0; i < NFCFileLines.length; i++) {
394: Normalizer.quickCheck(NFCFileLines[i],
395: Normalizer.NFD, 0);
396: }
397: }
398:
399: public long getOperationsPerIteration() {
400: int totalChars = 0;
401: for (int i = 0; i < NFCFileLines.length; i++) {
402: totalChars = totalChars + NFCFileLines[i].length();
403: }
404: return totalChars;
405: }
406: };
407: }
408:
409: PerfTest.Function TestQC_NFD_Orig_Text() {
410: return new PerfTest.Function() {
411: public void call() {
412: for (int i = 0; i < fileLines.length; i++) {
413: Normalizer.quickCheck(fileLines[i], Normalizer.NFD,
414: 0);
415: }
416: }
417:
418: public long getOperationsPerIteration() {
419: int totalChars = 0;
420: for (int i = 0; i < fileLines.length; i++) {
421: totalChars = totalChars + fileLines[i].length();
422: }
423: return totalChars;
424: }
425: };
426: }
427:
428: PerfTest.Function TestQC_FCD_NFD_Text() {
429: return new PerfTest.Function() {
430: public void call() {
431: for (int i = 0; i < NFDFileLines.length; i++) {
432: Normalizer.quickCheck(NFDFileLines[i],
433: Normalizer.FCD, 0);
434: }
435: }
436:
437: public long getOperationsPerIteration() {
438: int totalChars = 0;
439: for (int i = 0; i < NFDFileLines.length; i++) {
440: totalChars = totalChars + NFDFileLines[i].length();
441: }
442: return totalChars;
443: }
444: };
445: }
446:
447: PerfTest.Function TestQC_FCD_NFC_Text() {
448: return new PerfTest.Function() {
449: public void call() {
450: for (int i = 0; i < NFCFileLines.length; i++) {
451: Normalizer.quickCheck(NFCFileLines[i],
452: Normalizer.FCD, 0);
453: }
454: }
455:
456: public long getOperationsPerIteration() {
457: int totalChars = 0;
458: for (int i = 0; i < NFCFileLines.length; i++) {
459: totalChars = totalChars + NFCFileLines[i].length();
460: }
461: return totalChars;
462: }
463: };
464: }
465:
466: PerfTest.Function TestQC_FCD_Orig_Text() {
467: return new PerfTest.Function() {
468: public void call() {
469: for (int i = 0; i < fileLines.length; i++) {
470: Normalizer.quickCheck(fileLines[i], Normalizer.FCD,
471: 0);
472: }
473: }
474:
475: public long getOperationsPerIteration() {
476: int totalChars = 0;
477: for (int i = 0; i < fileLines.length; i++) {
478: totalChars = totalChars + fileLines[i].length();
479: }
480: return totalChars;
481: }
482: };
483: }
484:
485: // Test isNormalized Performance
486: PerfTest.Function TestIsNormalized_NFC_NFD_Text() {
487: return new PerfTest.Function() {
488: public void call() {
489: for (int i = 0; i < NFDFileLines.length; i++) {
490: Normalizer.isNormalized(NFDFileLines[i],
491: Normalizer.NFC, 0);
492: }
493: }
494:
495: public long getOperationsPerIteration() {
496: int totalChars = 0;
497: for (int i = 0; i < NFDFileLines.length; i++) {
498: totalChars = totalChars + NFDFileLines[i].length();
499: }
500: return totalChars;
501: }
502: };
503: }
504:
505: PerfTest.Function TestIsNormalized_NFC_NFC_Text() {
506: return new PerfTest.Function() {
507: public void call() {
508: for (int i = 0; i < NFCFileLines.length; i++) {
509: Normalizer.isNormalized(NFCFileLines[i],
510: Normalizer.NFC, 0);
511: }
512: }
513:
514: public long getOperationsPerIteration() {
515: int totalChars = 0;
516: for (int i = 0; i < NFCFileLines.length; i++) {
517: totalChars = totalChars + NFCFileLines[i].length();
518: }
519: return totalChars;
520: }
521: };
522: }
523:
524: PerfTest.Function TestIsNormalized_NFC_Orig_Text() {
525: return new PerfTest.Function() {
526: public void call() {
527: for (int i = 0; i < fileLines.length; i++) {
528: Normalizer.isNormalized(fileLines[i],
529: Normalizer.NFC, 0);
530: }
531: }
532:
533: public long getOperationsPerIteration() {
534: int totalChars = 0;
535: for (int i = 0; i < fileLines.length; i++) {
536: totalChars = totalChars + fileLines[i].length();
537: }
538: return totalChars;
539: }
540: };
541: }
542:
543: PerfTest.Function TestIsNormalized_NFD_NFD_Text() {
544: return new PerfTest.Function() {
545: public void call() {
546: for (int i = 0; i < NFDFileLines.length; i++) {
547: Normalizer.isNormalized(NFDFileLines[i],
548: Normalizer.NFD, 0);
549: }
550: }
551:
552: public long getOperationsPerIteration() {
553: int totalChars = 0;
554: for (int i = 0; i < NFDFileLines.length; i++) {
555: totalChars = totalChars + NFDFileLines[i].length();
556: }
557: return totalChars;
558: }
559: };
560: }
561:
562: PerfTest.Function TestIsNormalized_NFD_NFC_Text() {
563: return new PerfTest.Function() {
564: public void call() {
565: for (int i = 0; i < NFCFileLines.length; i++) {
566: Normalizer.isNormalized(NFCFileLines[i],
567: Normalizer.NFD, 0);
568: }
569: }
570:
571: public long getOperationsPerIteration() {
572: int totalChars = 0;
573: for (int i = 0; i < NFCFileLines.length; i++) {
574: totalChars = totalChars + NFCFileLines[i].length();
575: }
576: return totalChars;
577: }
578: };
579: }
580:
581: PerfTest.Function TestIsNormalized_NFD_Orig_Text() {
582: return new PerfTest.Function() {
583: public void call() {
584: for (int i = 0; i < fileLines.length; i++) {
585: Normalizer.isNormalized(fileLines[i],
586: Normalizer.NFD, 0);
587: }
588: }
589:
590: public long getOperationsPerIteration() {
591: int totalChars = 0;
592: for (int i = 0; i < fileLines.length; i++) {
593: totalChars = totalChars + fileLines[i].length();
594: }
595: return totalChars;
596: }
597: };
598: }
599:
600: PerfTest.Function TestIsNormalized_FCD_NFD_Text() {
601: return new PerfTest.Function() {
602: public void call() {
603: for (int i = 0; i < NFDFileLines.length; i++) {
604: Normalizer.isNormalized(NFDFileLines[i],
605: Normalizer.FCD, 0);
606: }
607: }
608:
609: public long getOperationsPerIteration() {
610: int totalChars = 0;
611: for (int i = 0; i < NFDFileLines.length; i++) {
612: totalChars = totalChars + NFDFileLines[i].length();
613: }
614: return totalChars;
615: }
616: };
617: }
618:
619: PerfTest.Function TestIsNormalized_FCD_NFC_Text() {
620: return new PerfTest.Function() {
621: public void call() {
622: for (int i = 0; i < NFCFileLines.length; i++) {
623: Normalizer.isNormalized(NFCFileLines[i],
624: Normalizer.FCD, 0);
625: }
626: }
627:
628: public long getOperationsPerIteration() {
629: int totalChars = 0;
630: for (int i = 0; i < NFCFileLines.length; i++) {
631: totalChars = totalChars + NFCFileLines[i].length();
632: }
633: return totalChars;
634: }
635: };
636: }
637:
638: PerfTest.Function TestIsNormalized_FCD_Orig_Text() {
639: return new PerfTest.Function() {
640: public void call() {
641: for (int i = 0; i < fileLines.length; i++) {
642: Normalizer.isNormalized(fileLines[i],
643: Normalizer.FCD, 0);
644: }
645: }
646:
647: public long getOperationsPerIteration() {
648: int totalChars = 0;
649: for (int i = 0; i < fileLines.length; i++) {
650: totalChars = totalChars + fileLines[i].length();
651: }
652: return totalChars;
653: }
654: };
655: }
656:
657: private void printUsage() {
658: System.out
659: .println("Usage: "
660: + this .getClass().getName()
661: + " [OPTIONS] fileName\n"
662: + "\t-f or --fileName \tfile to be used as test data\n"
663: + "\t-s or --sourceDir \tsource directory for files followed by path\n"
664: + "\t-e or --encoding \tencoding of source files\n"
665: + "\t-b or --bulkMode \tnormalize whole file at once\n"
666: + "\t-l or --lineMode \tnormalize file one line at a time\n");
667: System.exit(1);
668: }
669:
670: String[] normalizeInput(String[] src, Normalizer.Mode mode) {
671: String[] dest = new String[src.length];
672: for (int i = 0; i < src.length; i++) {
673: dest[i] = Normalizer.normalize(src[i], mode);
674: }
675:
676: return dest;
677: }
678: }
|