View Javadoc
1   package org.codehaus.plexus.util;
2   
3   /*
4    * Copyright 2011 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * <p>PerfTest class.</p>
23   *
24   * @author herve
25   * @version $Id: $Id
26   * @since 3.4.0
27   */
28  public class PerfTest {
29      String src = "012345578901234556789012345678901234456789012345678901234567890";
30  
31      private final int oops = 100;
32  
33      /**
34       * <p>testSubString.</p>
35       */
36      @Test
37      public void testSubString() {
38          StringBuilder res = new StringBuilder();
39          int len = src.length();
40          for (int cnt = 0; cnt < oops; cnt++) {
41              for (int i = 0; i < len - 5; i++) {
42                  res.append(src.substring(i, i + 4));
43              }
44          }
45          int i = res.length();
46          System.out.println("i = " + i);
47      }
48  
49      /**
50       * <p>testResDir.</p>
51       */
52      @Test
53      public void testResDir() {
54          StringBuilder res = new StringBuilder();
55          int len = src.length();
56          for (int cnt = 0; cnt < oops; cnt++) {
57              for (int i = 0; i < len - 5; i++) {
58                  res.append(src, i, i + 4);
59              }
60          }
61          int i = res.length();
62          System.out.println("i = " + i);
63      }
64  }