-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks for all processors so far...
- Loading branch information
Joshua J. A. Harwood
committed
Feb 15, 2024
1 parent
b8181cd
commit b88dcec
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/test/java/com/joshuaharwood/cifparser/processing/CifProcessorBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.joshuaharwood.cifparser.processing; | ||
|
||
import com.joshuaharwood.cifparser.parsing.files.CifCustomExecutorMultithreadedBatchingProcessor; | ||
import com.joshuaharwood.cifparser.parsing.files.CifCustomExecutorMultithreadedBatchingProcessor.CifMultithreadedBatchingProcessorConfig; | ||
import com.joshuaharwood.cifparser.parsing.files.CifCustomExecutorMultithreadedProcessor; | ||
import com.joshuaharwood.cifparser.parsing.files.CifCustomExecutorMultithreadedProcessor.CifMultithreadedProcessorConfig; | ||
import com.joshuaharwood.cifparser.parsing.files.CifDefaultMultithreadedProcessor; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.concurrent.ForkJoinPool; | ||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Timeout; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Threads(Threads.MAX) | ||
@BenchmarkMode(Mode.SingleShotTime) | ||
@Timeout(time = 1, timeUnit = TimeUnit.MINUTES) | ||
@Warmup(iterations = 2) | ||
public class CifProcessorBenchmark { | ||
|
||
private static final CifCustomExecutorMultithreadedBatchingProcessor CIF_CUSTOM_EXECUTOR_MULTITHREADED_BATCHING_PROCESSOR = new CifCustomExecutorMultithreadedBatchingProcessor( | ||
new CifMultithreadedBatchingProcessorConfig(new ForkJoinPool(), | ||
Runtime.getRuntime().availableProcessors())); | ||
|
||
private static final CifCustomExecutorMultithreadedProcessor CIF_CUSTOM_EXECUTOR_MULTITHREADED_PROCESSOR = new CifCustomExecutorMultithreadedProcessor( | ||
new CifMultithreadedProcessorConfig(new ForkJoinPool(), | ||
Runtime.getRuntime().availableProcessors())); | ||
|
||
private static final CifDefaultMultithreadedProcessor CIF_DEFAULT_MULTITHREADED_PROCESSOR = new CifDefaultMultithreadedProcessor(); | ||
|
||
/** | ||
* To use this, you'll need to download the latest CIF extract yourself and put it in the test | ||
* resources. | ||
*/ | ||
private static final URL FULL_CIF_PATH = Thread.currentThread() | ||
.getContextClassLoader() | ||
.getResource("toc-full.CIF"); | ||
|
||
public static void main(String[] args) throws Exception { | ||
org.openjdk.jmh.Main.main(args); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkCustomExecutorMultithreadedBatchingProcessor(Blackhole bh) throws Exception { | ||
assert FULL_CIF_PATH != null; | ||
|
||
bh.consume(CIF_CUSTOM_EXECUTOR_MULTITHREADED_BATCHING_PROCESSOR.parseCifRecords(getCifFileUri()) | ||
.get()); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkCustomExecutorMultithreadedProcessor(Blackhole bh) throws Exception { | ||
assert FULL_CIF_PATH != null; | ||
|
||
bh.consume(CIF_CUSTOM_EXECUTOR_MULTITHREADED_PROCESSOR.parseCifRecords(getCifFileUri()).get()); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkDefaultMultithreadedProcessor(Blackhole bh) throws Exception { | ||
assert FULL_CIF_PATH != null; | ||
|
||
bh.consume(CIF_DEFAULT_MULTITHREADED_PROCESSOR.parseCifRecords(getCifFileUri())); | ||
} | ||
|
||
private Path getCifFileUri() { | ||
try { | ||
return Path.of(Objects.requireNonNull(Thread.currentThread() | ||
.getContextClassLoader() | ||
.getResource("toc-full.CIF")).toURI()); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |