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   * @since 3.4.0
26   */
27  class PerfTest {
28      String src = "012345578901234556789012345678901234456789012345678901234567890";
29  
30      private final int oops = 100;
31  
32      @Test
33      void subString() {
34          StringBuilder res = new StringBuilder();
35          int len = src.length();
36          for (int cnt = 0; cnt < oops; cnt++) {
37              for (int i = 0; i < len - 5; i++) {
38                  res.append(src, i, i + 4);
39              }
40          }
41          int i = res.length();
42          System.out.println("i = " + i);
43      }
44  
45      @Test
46      void resDir() {
47          StringBuilder res = new StringBuilder();
48          int len = src.length();
49          for (int cnt = 0; cnt < oops; cnt++) {
50              for (int i = 0; i < len - 5; i++) {
51                  res.append(src, i, i + 4);
52              }
53          }
54          int i = res.length();
55          System.out.println("i = " + i);
56      }
57  }