diff --git a/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random/Randoms.java b/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random/Randoms.java index bd354fe4d..13b243805 100644 --- a/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random/Randoms.java +++ b/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random/Randoms.java @@ -78,7 +78,7 @@ public static int nextInt(int bound) { return current().nextInt(bound); } - private static Random create(long seed) { + public static Random create(long seed) { if (USE_JQWIK_ENGINE) { SEED.set(seed); return SourceOfRandomness.create(String.valueOf(seed)); diff --git a/fixture-monkey-benchmarks/fixture-monkey-benchmark/src/jmh/java/com/navercorp/fixturemonkey/SeedBenchmark.java b/fixture-monkey-benchmarks/fixture-monkey-benchmark/src/jmh/java/com/navercorp/fixturemonkey/SeedBenchmark.java new file mode 100644 index 000000000..d8def9670 --- /dev/null +++ b/fixture-monkey-benchmarks/fixture-monkey-benchmark/src/jmh/java/com/navercorp/fixturemonkey/SeedBenchmark.java @@ -0,0 +1,73 @@ +/* + * Fixture Monkey + * + * Copyright (c) 2021-present NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.fixturemonkey; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Level; +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.infra.Blackhole; + +import com.navercorp.fixturemonkey.api.random.Randoms; +import com.navercorp.fixturemonkey.api.type.TypeCache; +import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Benchmark) +public class SeedBenchmark { + private static final int seed = 1234; + private static final int COUNT = 500; + private static final FixtureMonkey SUT = FixtureMonkey.builder() + .plugin(new JavaxValidationPlugin()) + .seed(1234) + .build(); + + @Setup(value = Level.Iteration) + public void setUp() { + TypeCache.clearCache(); + } + + @Benchmark + public void eachIterationCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { + Randoms.create(Randoms.nextInt(Integer.MAX_VALUE)); + blackhole.consume(generateOrderSheet()); + } + + @Benchmark + public void eachIterationNotCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { + blackhole.consume(generateOrderSheet()); + } + + private List generateOrderSheet() { + List result = new ArrayList<>(); + for (int i = 0; i < COUNT; i++) { + result.add(SeedBenchmark.SUT.giveMeOne(OrderSheet.class)); + } + return result; + } +}