Skip to content

Commit

Permalink
测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
Saukiya committed Oct 19, 2024
1 parent f6cfc45 commit e2215cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
58 changes: 30 additions & 28 deletions src/test/java/github/saukiya/test/TestRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import github.saukiya.sxitem.SXItem;
import github.saukiya.sxitem.data.random.RandomDocker;
import github.saukiya.sxitem.util.Config;
import github.saukiya.util.TestBenchmark;
import github.saukiya.util.base.CharStack;
import github.saukiya.util.base.DoubleStack;
import github.saukiya.util.helper.PlaceholderHelper;
import lombok.val;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.file.YamlConfiguration;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -31,13 +34,15 @@ public class TestRandom {

static List<String> copyList = Arrays.asList("|||||||||||||", "|||||||||||||||", "||||||||||\n|||||||||||", "||||||||||||||||", "|||||||||||||||||||||", "||||||||||\n|||||||||||", "|||||||||||||||||||||", "||||||||\n|||||||\n||||||", "|||||||||||||||||||||");

@Setup(Level.Trial)
public static void setupTrial() throws Exception {
YamlConfiguration config = new YamlConfiguration();
config.set(Config.TIME_FORMAT, "yyyy/MM/dd HH:mm");
val temp = Config.class.getDeclaredField("config");
temp.setAccessible(true);
temp.set(null, config);
static {
try {
YamlConfiguration config = new YamlConfiguration();
config.set(Config.TIME_FORMAT, "yyyy/MM/dd HH:mm");
Field temp = Config.class.getDeclaredField("config");
temp.setAccessible(true);
temp.set(null, config);
} catch (Exception e) {
}
}

public static void main(String[] args) throws Exception {
Expand All @@ -49,7 +54,7 @@ public static void main(String[] args) throws Exception {
// TestBenchmark.run(IntBM.class);
// TestBenchmark.run(LockBM.class);
// TestBenchmark.run("BooleanBM.test3", "CalculatorBM.test3", "TimeBM.test3", "DoubleBM.test3", "IntegerBM.test3", "LockBM.test2");
TestBenchmark.run("test1", "test2");
// TestBenchmark.run("replace1", "replace2");
// TestBenchmark.run();
// calculatorValidation();
// System.out.println(boolean1("AAA:BBB:CCC:DDD:EEE:AAA") != null);
Expand All @@ -58,21 +63,18 @@ public static void main(String[] args) throws Exception {
// System.out.println(boolean3("AAA:BBB:CCC:DDD:EEE:AAA") != null);
// System.out.println(boolean3("AAA:BBB:CCC:DDD:EEE:AAAA") != null);
// System.out.println(boolean3("AA#AAA:BB:CC:DD:EE:FF:GG:HH:YY:GG:KK:AA") != null);

System.out.println(test1());
System.out.println(test2());
}

@Benchmark
public static Object test1() {
public static Object replace1() {
return copyList.stream()
.flatMap(str -> str.indexOf('\n') != -1 ? Arrays.stream(str.split("\n")) : Stream.of(str))
.filter(s -> !s.contains("%DeleteLore"))
.collect(Collectors.toList());
}

@Benchmark
public static Object test2() {
public static Object replace2() {
val list = new ArrayList<>();
for (String str : copyList) {
if (str.indexOf('\n') != -1) {
Expand Down Expand Up @@ -549,7 +551,7 @@ public static String lock2(String key, RandomDocker docker) {
@State(Scope.Thread)
public static class LockBM {
@Param({"KEY#100:200:300"})
String key = "KEY#100:200:300";
String key;
RandomDocker docker = new RandomDocker();

@Benchmark
Expand All @@ -565,8 +567,8 @@ public void test2() {

@State(Scope.Thread)
public static class IntBM {
@Param({"1_2", "200_100"})
String key = "1_2";
@Param({"10_20"})
String key;

@Benchmark
public void test1() {
Expand All @@ -581,8 +583,8 @@ public void test3() {

@State(Scope.Thread)
public static class DoubleBM {
@Param({"1.5_2.5", "200_100"})
String key = "1.5_2.5";
@Param({"1.5_15.5"})
String key;

@Benchmark
public void test1() {
Expand All @@ -597,8 +599,8 @@ public void test3() {

@State(Scope.Thread)
public static class TimeBM {
@Param({"20Y12M31D23h59m59s", "12345"})
String key = "20Y12M31D23h59m59s";
@Param({"20Y12M31D23h59m59s"})
String key;

@Benchmark
public void test1() {
Expand All @@ -613,8 +615,8 @@ public void test3() {

@State(value = Scope.Thread)
public static class CalculatorBM {
@Param({"12 + 24 - 36 * 2 / (4 + 6) % 3", "-3 + ((4 * (10 - (6 / 2))) - (8 % 3) + (5 + (-7) / 2))"})
String key = "- (3 - (- (4 + 5) ) )";
@Param({"-3 + ((4 * (10 - (6 / 2))) - (8 % 3) + (5 + (-7) / 2))"})
String key;

@Benchmark
public void test1() {
Expand All @@ -629,8 +631,8 @@ public void test3() {

@State(value = Scope.Thread)
public static class BooleanBM {
@Param({"AA:AAA:BB:CC:DD:EE:FF:GG:HH:YY:GG:KK:AA", "AA:BB:AA:DD:A:FF:GG:HH:AAA"})
String key = "AA:AAA:BB:CC:DD:EE:FF:GG:HH:YY:GG:KK:AA";
@Param({"AA:AAA:BB:CC:DD:EE:FF:GG:AA:HH:YY:GG:KK"})
String key;

@Benchmark
public void test1() {
Expand All @@ -645,8 +647,8 @@ public void test3() {

@State(value = Scope.Thread)
public static class ScriptBM {
@Param({"File.function#AAA,BBB", "File.function#AAA,BBB,CCC"})
String key = "File.function#AAA,BBB";
@Param({"File.function#AAA,BBB,CCC"})
String key;

@Benchmark
public void test1() {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/github/saukiya/util/TestBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.val;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
Expand Down Expand Up @@ -51,7 +50,7 @@ private static ChainedOptionsBuilder builder() {
.mode(Mode.AverageTime)
.threads(2)
.forks(1)
.addProfiler(GCProfiler.class)
// .addProfiler(GCProfiler.class)
;
}
}

0 comments on commit e2215cf

Please sign in to comment.