Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created November 3, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/860de09b6c94b68ede8018c27969f962 to your computer and use it in GitHub Desktop.
Save purplefox/860de09b6c94b68ede8018c27969f962 to your computer and use it in GitHub Desktop.
/*
* 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 = 4, time = 10)
@Measurement(iterations = 4, time = 10)
@Threads(2)
@Fork(3)
public class ArrayInitBenchmark {
private static final ArrayList<Integer> sarr1 =
new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
@Benchmark
public ArrayList<Integer> initArray1() {
ArrayList<Integer> arr2 = new ArrayList<>(sarr1);
arr2.add(10);
arr2.add(11);
return arr2;
}
@Benchmark
public ArrayList<Integer> initArray2() {
ArrayList<Integer> arr2 = new ArrayList<>(20);
for (Integer i: sarr1) {
arr2.add(i);
}
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment