Skip to content

Commit 5519141

Browse files
committed
Add the benchmark related to seed
1 parent dcd98dd commit 5519141

File tree

2 files changed

+74
-1
lines changed
  • fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random
  • fixture-monkey-benchmarks/fixture-monkey-benchmark/src/jmh/java/com/navercorp/fixturemonkey

2 files changed

+74
-1
lines changed

fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/random/Randoms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static int nextInt(int bound) {
7878
return current().nextInt(bound);
7979
}
8080

81-
private static Random create(long seed) {
81+
public static Random create(long seed) {
8282
if (USE_JQWIK_ENGINE) {
8383
SEED.set(seed);
8484
return SourceOfRandomness.create(String.valueOf(seed));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)