-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IntArrayList to store tokens without boxing
Before: Benchmark (dataFolderPath) Mode Cnt Score Error Units SingleThreadedBenchmark.benchmarkCl100kBase data ss 10 3.263 ± 0.286 s/op SingleThreadedBenchmark.benchmarkCl100kBaseTokenCount data ss 10 2.688 ± 0.054 s/op SingleThreadedBenchmark.benchmarkP50kBase data ss 10 5.335 ± 0.106 s/op SingleThreadedBenchmark.benchmarkP50kEdit data ss 10 5.277 ± 0.067 s/op SingleThreadedBenchmark.benchmarkR50kBase data ss 10 5.002 ± 0.091 s/op After: Benchmark (dataFolderPath) Mode Cnt Score Error Units SingleThreadedBenchmark.benchmarkCl100kBase data ss 10 2.498 ± 0.019 s/op SingleThreadedBenchmark.benchmarkCl100kBaseTokenCount data ss 10 2.223 ± 0.014 s/op SingleThreadedBenchmark.benchmarkP50kBase data ss 10 4.354 ± 0.122 s/op SingleThreadedBenchmark.benchmarkP50kEdit data ss 10 4.341 ± 0.076 s/op SingleThreadedBenchmark.benchmarkR50kBase data ss 10 4.068 ± 0.020 s/op
- Loading branch information
Lőrinc
committed
Dec 30, 2023
1 parent
fec3eeb
commit aee505c
Showing
18 changed files
with
364 additions
and
116 deletions.
There are no files selected for viewing
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
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
56 changes: 29 additions & 27 deletions
56
benchmark/src/jmh/java/com/knuddels/jtokkit/AbstractMultiThreadedBenchmark.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 |
---|---|---|
@@ -1,46 +1,48 @@ | ||
package com.knuddels.jtokkit; | ||
|
||
import com.knuddels.jtokkit.api.Encoding; | ||
import com.knuddels.jtokkit.api.IntArrayList; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.stream.Collectors; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
|
||
@State(Scope.Thread) | ||
public abstract class AbstractMultiThreadedBenchmark extends AbstractBenchmark { | ||
|
||
private final int threads; | ||
private ExecutorService executor; | ||
private final int threads; | ||
private ExecutorService executor; | ||
|
||
public AbstractMultiThreadedBenchmark(final int threads) { | ||
this.threads = threads; | ||
} | ||
public AbstractMultiThreadedBenchmark(int threads) { | ||
this.threads = threads; | ||
} | ||
|
||
@Setup | ||
public void setup() { | ||
executor = Executors.newFixedThreadPool(threads); | ||
} | ||
@Setup | ||
public void setup() { | ||
executor = Executors.newFixedThreadPool(threads); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() { | ||
executor.shutdown(); | ||
} | ||
@TearDown | ||
public void tearDown() { | ||
executor.shutdown(); | ||
} | ||
|
||
@Override | ||
protected List<List<Integer>> encodeAll(final Encoding encoding, final List<String> fileContents) { | ||
final var futures = fileContents.stream() | ||
.map(it -> CompletableFuture.supplyAsync(() -> encoding.encode(it), executor)) | ||
.collect(Collectors.toList()); | ||
@Override | ||
protected List<IntArrayList> encodeAll(Encoding encoding, List<String> fileContents) { | ||
var futures = fileContents.stream() | ||
.map(it -> CompletableFuture.supplyAsync(() -> encoding.encode(it), executor)) | ||
.toList(); | ||
|
||
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).join(); | ||
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).join(); | ||
|
||
return futures.stream() | ||
.map(CompletableFuture::join) | ||
.collect(Collectors.toList()); | ||
} | ||
return futures.stream() | ||
.map(CompletableFuture::join) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.