1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.codec.language.bm; 18 19 import org.junit.jupiter.api.Test; 20 21 /** 22 * Tests performance for {@link PhoneticEngine}. 23 * <p> 24 * See <a href="https://issues.apache.org/jira/browse/CODEC-174">[CODEC-174] Improve performance of Beider Morse 25 * encoder</a>. 26 * </p> 27 * <p> 28 * Results for November 7, 2013, project SVN revision 1539678. 29 * </p> 30 * <p> 31 * Environment: 32 * </p> 33 * <ul> 34 * <li>java version "1.7.0_45"</li> 35 * <li>Java(TM) SE Runtime Environment (build 1.7.0_45-b18)</li> 36 * <li>Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)</li> 37 * <li>OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows")</li> 38 * </ul> 39 * <ol> 40 * <li>Time for encoding 80,000 times the input 'Angelo': 33,039 millis.</li> 41 * <li>Time for encoding 80,000 times the input 'Angelo': 32,297 millis.</li> 42 * <li>Time for encoding 80,000 times the input 'Angelo': 32,857 millis.</li> 43 * <li>Time for encoding 80,000 times the input 'Angelo': <b>31,561 millis.</b></li> 44 * <li>Time for encoding 80,000 times the input 'Angelo': 32,665 millis.</li> 45 * <li>Time for encoding 80,000 times the input 'Angelo': 32,215 millis.</li> 46 * </ol> 47 * <p> 48 * On this file's revision 1539678, with patch <a 49 * href="https://issues.apache.org/jira/secure/attachment/12611963/CODEC-174-change-rules-storage-to-Map.patch" 50 * >CODEC-174-change-rules-storage-to-Map</a>: 51 * </p> 52 * <ol> 53 * <li>Time for encoding 80,000 times the input 'Angelo': 18,196 millis.</li> 54 * <li>Time for encoding 80,000 times the input 'Angelo': 13,858 millis.</li> 55 * <li>Time for encoding 80,000 times the input 'Angelo': 13,644 millis.</li> 56 * <li>Time for encoding 80,000 times the input 'Angelo': <b>13,591 millis.</b></li> 57 * <li>Time for encoding 80,000 times the input 'Angelo': 13,861 millis.</li> 58 * <li>Time for encoding 80,000 times the input 'Angelo': 13,696 millis.</li> 59 * </ol> 60 * <p> 61 * Patch applied, committed revision 1539783. 62 * </p> 63 * <p> 64 * On this file's revision 1539783, with patch <a 65 * href="https://issues.apache.org/jira/secure/attachment/12611962/CODEC-174-delete-subsequence-cache.patch" 66 * >CODEC-174-delete-subsequence-cache.patch</a>: 67 * </p> 68 * <ol> 69 * <li>Time for encoding 80,000 times the input 'Angelo': 13,547 millis.</li> 70 * <li>Time for encoding 80,000 times the input 'Angelo': <b>13,501 millis.</b></li> 71 * <li>Time for encoding 80,000 times the input 'Angelo': 13,528 millis.</li> 72 * <li>Time for encoding 80,000 times the input 'Angelo': 17,110 millis.</li> 73 * <li>Time for encoding 80,000 times the input 'Angelo': 13,910 millis.</li> 74 * <li>Time for encoding 80,000 times the input 'Angelo': 16,969 millis.</li> 75 * </ol> 76 * <p> 77 * Patch not applied. 78 * </p> 79 * <p> 80 * On this file's revision 1539787, with patch <a 81 * href="https://issues.apache.org/jira/secure/attachment/12612178/CODEC-174-reuse-set-in-PhonemeBuilder.patch" 82 * >CODEC-174-reuse-set-in-PhonemeBuilder.patch</a>: 83 * </p> 84 * <ol> 85 * <li>Time for encoding 80,000 times the input 'Angelo': 13,724 millis.</li> 86 * <li>Time for encoding 80,000 times the input 'Angelo': 13,451 millis.</li> 87 * <li>Time for encoding 80,000 times the input 'Angelo': 13,742 millis.</li> 88 * <li>Time for encoding 80,000 times the input 'Angelo': <b>13,186 millis.</b></li> 89 * <li>Time for encoding 80,000 times the input 'Angelo': 13,600 millis.</li> 90 * <li>Time for encoding 80,000 times the input 'Angelo': 16,405 millis.</li> 91 * </ol> 92 * <p> 93 * Patch applied, committed revision 1539788. 94 * </p> 95 * <p> 96 * Before patch https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch 97 * </p> 98 * <ol> 99 * <li>Time for encoding 80,000 times the input 'Angelo': 13,133 millis.</li> 100 * <li>Time for encoding 80,000 times the input 'Angelo': 13,064 millis.</li> 101 * <li>Time for encoding 80,000 times the input 'Angelo': <b>12,838 millis.</b></li> 102 * <li>Time for encoding 80,000 times the input 'Angelo': 12,970 millis.</li> 103 * <li>Time for encoding 80,000 times the input 'Angelo': 13,122 millis.</li> 104 * <li>Time for encoding 80,000 times the input 'Angelo': 13,293 millis.</li> 105 * </ol> 106 * <p> 107 * After patch https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch 108 * </p> 109 * <ol> 110 * <li>Time for encoding 80,000 times the input 'Angelo': 11,576 millis.</li> 111 * <li>Time for encoding 80,000 times the input 'Angelo': 11,506 millis.</li> 112 * <li>Time for encoding 80,000 times the input 'Angelo': 11,361 millis.</li> 113 * <li>Time for encoding 80,000 times the input 'Angelo': <b>11,142 millis.</b></li> 114 * <li>Time for encoding 80,000 times the input 'Angelo': 11,430 millis.</li> 115 * <li>Time for encoding 80,000 times the input 'Angelo': 11,297 millis.</li> 116 * </ol> 117 * <p> 118 * Patch applied, committed revision 1541234. 119 * </p> 120 */ 121 public class PhoneticEnginePerformanceTest { 122 123 private static final int LOOP = 80000; 124 125 @Test 126 public void test() { 127 final PhoneticEngine engine = new PhoneticEngine(NameType.GENERIC, RuleType.APPROX, true); 128 final String input = "Angelo"; 129 final long startMillis = System.currentTimeMillis(); 130 for (int i = 0; i < LOOP; i++) { 131 engine.encode(input); 132 } 133 final long totalMillis = System.currentTimeMillis() - startMillis; 134 System.out.println(String.format("Time for encoding %,d times the input '%s': %,d millis.", LOOP, input, 135 totalMillis)); 136 } 137 }