@@ -0,0 +1,2569 @@
+/*%0A * Copyright (C) 2012 The Guava Authors%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.common.collect;%0A%0Aimport com.google.caliper.Param;%0Aimport com.google.caliper.Runner;%0Aimport com.google.caliper.SimpleBenchmark;%0A%0Aimport java.util.List;%0A%0A/**%0A * Benchmark for various ways to create an %7B@code ImmutableList%7D.%0A *%0A * @author Louis Wasserman%0A */%0Apublic class ImmutableListCreationBenchmark extends SimpleBenchmark %7B%0A%0A  @Param(%7B%2210%22, %221000%22, %221000000%22%7D)%0A  int size;%0A%0A  private static final Object OBJECT = new Object();%0A%0A  public int timeBuilderAdd(int reps) %7B%0A    int size = this.size;%0A    int dummy = 0;%0A    for (int rep = 0; rep %3C reps; rep++) %7B%0A      ImmutableList.Builder%3CObject%3E builder = ImmutableList.builder();%0A      for (int i = 0; i %3C size; i++) %7B%0A        builder.add(OBJECT);%0A      %7D%0A      dummy += builder.build().size();%0A    %7D%0A    return dummy;%0A  %7D%0A%0A  public int timePreSizedBuilderAdd(int reps) %7B%0A    int size = this.size;%0A    int dummy = 0;%0A    for (int rep = 0; rep %3C reps; rep++) %7B%0A      ImmutableList.Builder%3CObject%3E builder = new ImmutableList.Builder%3CObject%3E(size);%0A      for (int i = 0; i %3C size; i++) %7B%0A        builder.add(OBJECT);%0A      %7D%0A      dummy += builder.build().size();%0A    %7D%0A    return dummy;%0A  %7D%0A%0A  public int timeCopyArrayList(int reps) %7B%0A    int size = this.size;%0A    int dummy = 0;%0A    for (int rep = 0; rep %3C reps; rep++) %7B%0A      List%3CObject%3E builder = Lists.newArrayList();%0A      for (int i = 0; i %3C size; i++) %7B%0A        builder.add(OBJECT);%0A      %7D%0A      dummy += ImmutableList.copyOf(builder).size();%0A    %7D%0A    return dummy;%0A  %7D%0A%0A  public int timeCopyPreSizedArrayList(int reps) %7B%0A    int size = this.size;%0A    int tmp = 0;%0A    for (int rep = 0; rep %3C reps; rep++) %7B%0A      List%3CObject%3E builder = Lists.newArrayListWithCapacity(size);%0A      for (int i = 0; i %3C size; i++) %7B%0A        builder.add(OBJECT);%0A      %7D%0A      tmp += ImmutableList.copyOf(builder).size();%0A    %7D%0A    return tmp;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    Runner.main(ImmutableListCreationBenchmark.class, args);%0A  %7D%0A%7D%0A

Add ImmutableListCreationBenchmark to help evaluate the utility of pre-sized builders. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=36498026