-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
211 additions
and
282 deletions.
There are no files selected for viewing
136 changes: 68 additions & 68 deletions
136
eternaleconomy-core/src/jmh/java/com/eternalcode/economy/account/AccountBenchmark.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,68 +1,68 @@ | ||
package com.eternalcode.economy.account; | ||
|
||
import com.eternalcode.economy.account.database.AccountRepositoryInMemory; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
import java.util.UUID; | ||
|
||
@State(Scope.Thread) | ||
public class AccountBenchmark { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(AccountBenchmark.class.getName()); | ||
private static final char[] ALPHABET = "abcdefghijklmnopqrstuvwxyz".toCharArray(); | ||
|
||
private final List<String> searches = new ArrayList<>(); | ||
private AccountManager accountManager; | ||
|
||
@Setup | ||
public void setUp() { | ||
accountManager = new AccountManager(new AccountRepositoryInMemory()); | ||
|
||
// zapełnienie TreeMapy różnymi nazwami zapewnia, że będzie ona miała optymalne wyniki | ||
// tree mapa rozdziela elementy na podstawie ich klucza, więc im bardziej zróżnicowane klucze, tym "lepsze' wyniki | ||
for (char first : ALPHABET) { | ||
for (char second : ALPHABET) { | ||
for (char third : ALPHABET) { | ||
String name = String.valueOf(first) + second + third; | ||
|
||
accountManager.create(UUID.randomUUID(), name); | ||
} | ||
} | ||
} | ||
|
||
// pre-generowanie losowych wyszukiwań, które będą wykonywane w benchmarku (nie wpływamy na czas wykonania samego benchmarku) | ||
for (char first : ALPHABET) { | ||
searches.add(String.valueOf(first)); | ||
for (char second : ALPHABET) { | ||
searches.add(String.valueOf(first) + second); | ||
for (char third : ALPHABET) { | ||
searches.add(String.valueOf(first) + second + third); | ||
} | ||
} | ||
} | ||
|
||
Collections.shuffle(searches); // mieszamy, aby zapewnić losowy dostęp | ||
|
||
LOGGER.info("Acounts size: " + accountManager.getAccounts().size() + ", Searches size: " + searches.size()); | ||
} | ||
|
||
// mimo że nie jest to bezpieczne dla wielu wątków, to w przypadku JMH można to zignorować i tak potrzebujemy losowości | ||
private int index = 0; | ||
|
||
@Benchmark | ||
@Warmup(iterations = 5, time = 1) | ||
@Measurement(iterations = 10, time = 1) | ||
public void benchmarkGetAccountStartingWith() { | ||
accountManager.getAccountStartingWith(searches.get(index++ % searches.size())); | ||
} | ||
|
||
} | ||
// package com.eternalcode.economy.account; | ||
// | ||
// import com.eternalcode.economy.account.database.AccountRepositoryInMemory; | ||
// import java.util.ArrayList; | ||
// import java.util.Collections; | ||
// import java.util.List; | ||
// import java.util.logging.Logger; | ||
// import org.openjdk.jmh.annotations.Benchmark; | ||
// import org.openjdk.jmh.annotations.Setup; | ||
// import org.openjdk.jmh.annotations.State; | ||
// import org.openjdk.jmh.annotations.Scope; | ||
// import org.openjdk.jmh.annotations.Measurement; | ||
// import org.openjdk.jmh.annotations.Warmup; | ||
// | ||
// import java.util.UUID; | ||
// | ||
// @State(Scope.Thread) | ||
// public class AccountBenchmark { | ||
// | ||
// private static final Logger LOGGER = Logger.getLogger(AccountBenchmark.class.getName()); | ||
// private static final char[] ALPHABET = "abcdefghijklmnopqrstuvwxyz".toCharArray(); | ||
// | ||
// private final List<String> searches = new ArrayList<>(); | ||
// private AccountManager accountManager; | ||
// | ||
// @Setup | ||
// public void setUp() { | ||
// accountManager = new AccountManager(new AccountRepositoryInMemory()); | ||
// | ||
// // zapełnienie TreeMapy różnymi nazwami zapewnia, że będzie ona miała optymalne wyniki | ||
// // tree mapa rozdziela elementy na podstawie ich klucza, więc im bardziej zróżnicowane klucze, tym "lepsze' wyniki | ||
// for (char first : ALPHABET) { | ||
// for (char second : ALPHABET) { | ||
// for (char third : ALPHABET) { | ||
// String name = String.valueOf(first) + second + third; | ||
// | ||
// accountManager.create(UUID.randomUUID(), name); | ||
// } | ||
// } | ||
// } | ||
// | ||
// // pre-generowanie losowych wyszukiwań, które będą wykonywane w benchmarku (nie wpływamy na czas wykonania samego benchmarku) | ||
// for (char first : ALPHABET) { | ||
// searches.add(String.valueOf(first)); | ||
// for (char second : ALPHABET) { | ||
// searches.add(String.valueOf(first) + second); | ||
// for (char third : ALPHABET) { | ||
// searches.add(String.valueOf(first) + second + third); | ||
// } | ||
// } | ||
// } | ||
// | ||
// Collections.shuffle(searches); // mieszamy, aby zapewnić losowy dostęp | ||
// | ||
// LOGGER.info("Acounts size: " + accountManager.getAccounts().size() + ", Searches size: " + searches.size()); | ||
// } | ||
// | ||
// // mimo że nie jest to bezpieczne dla wielu wątków, to w przypadku JMH można to zignorować i tak potrzebujemy losowości | ||
// private int index = 0; | ||
// | ||
// @Benchmark | ||
// @Warmup(iterations = 5, time = 1) | ||
// @Measurement(iterations = 10, time = 1) | ||
// public void benchmarkGetAccountStartingWith() { | ||
// accountManager.getAccountStartingWith(searches.get(index++ % searches.size())); | ||
// } | ||
// | ||
// } |
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.