View Javadoc
1   /**
2    * Copyright 2014-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.jute.builder;
17  
18  import static com.google.common.base.Stopwatch.createStarted;
19  import static org.apache.commons.lang3.StringUtils.leftPad;
20  import static org.kuali.common.jute.base.Formats.getCount;
21  import static org.kuali.common.jute.base.Formats.getTime;
22  
23  import org.apache.commons.lang3.builder.Builder;
24  import org.junit.Test;
25  import org.kuali.common.jute.base.BaseUnitTest;
26  
27  import com.google.common.base.Stopwatch;
28  
29  public class BuilderTest extends BaseUnitTest {
30  
31      @Test
32      public void test() {
33          int count = 5000000;
34          info("     iterations -> %s", getCount(count));
35          build(FooUnchecked.builder(), count);
36          build(FooGuava1.builder(), count);
37          build(FooGuava2.builder(), count);
38          build(FooJute1.builder(), count);
39          build(FooJute2.builder(), count);
40          build(FooReflection.builder(), count);
41      }
42  
43      protected <T extends Builder<?>> void build(T builder, int count) {
44          Stopwatch sw = createStarted();
45          for (int i = 0; i < count; i++) {
46              builder.build();
47          }
48          info("%s -> %s", leftPad(builder.getClass().getDeclaringClass().getSimpleName(), 15), getTime(sw));
49      }
50  
51  }