|
| 1 | +/* |
| 2 | + * Fixture Monkey |
| 3 | + * |
| 4 | + * Copyright (c) 2021-present NAVER Corp. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.navercorp.fixturemonkey; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | +import java.util.concurrent.TimeUnit; |
| 24 | + |
| 25 | +import org.openjdk.jmh.annotations.Benchmark; |
| 26 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 27 | +import org.openjdk.jmh.annotations.Level; |
| 28 | +import org.openjdk.jmh.annotations.Mode; |
| 29 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 30 | +import org.openjdk.jmh.annotations.Scope; |
| 31 | +import org.openjdk.jmh.annotations.Setup; |
| 32 | +import org.openjdk.jmh.annotations.State; |
| 33 | +import org.openjdk.jmh.infra.Blackhole; |
| 34 | + |
| 35 | +import com.navercorp.fixturemonkey.api.random.Randoms; |
| 36 | +import com.navercorp.fixturemonkey.api.type.TypeCache; |
| 37 | +import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin; |
| 38 | + |
| 39 | +@BenchmarkMode(Mode.AverageTime) |
| 40 | +@OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 41 | +@State(Scope.Benchmark) |
| 42 | +public class SeedBenchmark { |
| 43 | + private static final int seed = 1234; |
| 44 | + private static final int COUNT = 500; |
| 45 | + private static final FixtureMonkey SUT = FixtureMonkey.builder() |
| 46 | + .plugin(new JavaxValidationPlugin()) |
| 47 | + .seed(1234) |
| 48 | + .build(); |
| 49 | + |
| 50 | + @Setup(value = Level.Iteration) |
| 51 | + public void setUp() { |
| 52 | + TypeCache.clearCache(); |
| 53 | + } |
| 54 | + |
| 55 | + @Benchmark |
| 56 | + public void eachIterationCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { |
| 57 | + Randoms.create(Randoms.nextInt(Integer.MAX_VALUE)); |
| 58 | + blackhole.consume(generateOrderSheet()); |
| 59 | + } |
| 60 | + |
| 61 | + @Benchmark |
| 62 | + public void eachIterationNotCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { |
| 63 | + blackhole.consume(generateOrderSheet()); |
| 64 | + } |
| 65 | + |
| 66 | + private List<OrderSheet> generateOrderSheet() { |
| 67 | + List<OrderSheet> result = new ArrayList<>(); |
| 68 | + for (int i = 0; i < COUNT; i++) { |
| 69 | + result.add(SeedBenchmark.SUT.giveMeOne(OrderSheet.class)); |
| 70 | + } |
| 71 | + return result; |
| 72 | + } |
| 73 | +} |
0 commit comments