/* * Copyright 2018 Confluent Inc. * * Licensed under the Confluent Community License (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of the * License at * * http://www.confluent.io/confluent-community-license * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package io.confluent.ksql.benchmark; import io.confluent.ksql.benchmark.UdfInvokerBenchmark.UdfInvokerState; import io.confluent.ksql.function.FunctionInvoker; import io.confluent.ksql.function.FunctionLoaderUtils; import io.confluent.ksql.function.udf.PluggableUdf; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 2, time = 10) @Measurement(iterations = 2, time = 10) @Threads(1) @Fork(1) public class ArrayInitBenchmark { private static final ArrayList sarr1 = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); @Benchmark public ArrayList initArray1() { ArrayList arr2 = new ArrayList<>(sarr1); arr2.add(10); arr2.add(11); return arr2; } @Benchmark public ArrayList initArray2() { ArrayList arr2 = new ArrayList<>(12); arr2.addAll(sarr1); arr2.add(10); arr2.add(11); return arr2; } public static void main(final String[] args) throws RunnerException { final Options opt = new OptionsBuilder() .include(ArrayInitBenchmark.class.getSimpleName()) .build(); new Runner(opt).run(); } }