Skip to content

Commit

Permalink
Add the benchmark related to seed
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Jan 13, 2025
1 parent dcd98dd commit 8347830
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 net.jqwik.engine.SourceOfRandomness;

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(Long.parseLong(SourceOfRandomness.createRandomSeed()));
blackhole.consume(generateOrderSheet());
}

@Benchmark
public void eachIterationNotCreatesNewJqwikSeed(Blackhole blackhole) throws Exception {
blackhole.consume(generateOrderSheet());
}

private List<OrderSheet> generateOrderSheet() {
List<OrderSheet> result = new ArrayList<>();
for (int i = 0; i < COUNT; i++) {
result.add(SeedBenchmark.SUT.giveMeOne(OrderSheet.class));
}
return result;
}
}

0 comments on commit 8347830

Please sign in to comment.