Skip to content

Commit 8b0318c

Browse files
committed
[CODEC-174] Improve performance of Beider Morse encoder. Add a performance test.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1539776 13f79535-47bb-0310-9956-ffa450edef68
1 parent d9ea80d commit 8b0318c

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ limitations under the License.
248248
<configuration>
249249
<excludes>
250250
<exclude>**/*AbstractTest.java</exclude>
251+
<exclude>**/*PerformanceTest.java</exclude>
251252
</excludes>
252253
</configuration>
253254
</plugin>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)