|
| 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.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 encoder</a>. |
| 25 | + * </p> |
| 26 | + * <p> |
| 27 | + * Results for November 7, 2013, SVN revision 1539678. |
| 28 | + * </p> |
| 29 | + * <ol> |
| 30 | + * <li>Time for encoding 80,000 times the input 'Angelo': 33,039 millis.</li> |
| 31 | + * <li>Time for encoding 80,000 times the input 'Angelo': 32,297 millis.</li> |
| 32 | + * <li>Time for encoding 80,000 times the input 'Angelo': 32,857 millis.</li> |
| 33 | + * <li>Time for encoding 80,000 times the input 'Angelo': 31,561 millis.</li> |
| 34 | + * <li>Time for encoding 80,000 times the input 'Angelo': 32,665 millis.</li> |
| 35 | + * <li>Time for encoding 80,000 times the input 'Angelo': 32,215 millis.</li> |
| 36 | + * </ol> |
| 37 | + */ |
| 38 | +public class PhoneticEnginePerformanceTest { |
| 39 | + |
| 40 | + private static final int LOOP = 80000; |
| 41 | + |
| 42 | + @Test |
| 43 | + public void test() { |
| 44 | + PhoneticEngine engine = new PhoneticEngine(NameType.GENERIC, RuleType.APPROX, true); |
| 45 | + final String input = "Angelo"; |
| 46 | + final long startMillis = System.currentTimeMillis(); |
| 47 | + for (int i = 0; i < LOOP; i++) { |
| 48 | + engine.encode(input); |
| 49 | + } |
| 50 | + final long totalMillis = System.currentTimeMillis() - startMillis; |
| 51 | + System.out.println(String.format("Time for encoding %,d times the input '%s': %,d millis.", LOOP, input, |
| 52 | + totalMillis)); |
| 53 | + } |
| 54 | +} |
0 commit comments