Skip to content

Commit

Permalink
- optimize benchmark use @Param
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Jan 5, 2022
1 parent 4534fce commit f6173ed
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 584 deletions.
8 changes: 4 additions & 4 deletions cosid-core/src/jmh/java/me/ahoo/cosid/SegmentIdBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class SegmentIdBenchmark {

SegmentId segmentId;
SegmentChainId segmentChainId;
AtomicLongGenerator jdkId;
AtomicLongGenerator atomicLongGenerator;

@Setup
public void setup() {
jdkId = new AtomicLongGenerator();
atomicLongGenerator = new AtomicLongGenerator();
segmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
segmentChainId = new SegmentChainId(TIME_TO_LIVE_FOREVER, 10, new IdSegmentDistributor.Mock(), PrefetchWorkerExecutorService.DEFAULT);
}
Expand All @@ -52,8 +52,8 @@ public UUID uuid_generate() {
}

@Benchmark
public long jdkId_generate() {
return jdkId.generate();
public long atomicLong_generate() {
return atomicLongGenerator.generate();
}

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion cosid-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ dependencies {
implementation("com.google.guava:guava")
implementation("org.springframework.boot:spring-boot-starter-web")
compileOnly("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${rootProject.ext.get("springBootVersion")}")
annotationProcessor("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${rootProject.ext.get("springBootVersion")}")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,28 @@

package me.ahoo.cosid.jdbc;

import me.ahoo.cosid.jdbc.state.JdkIdState;
import me.ahoo.cosid.jdbc.state.SegmentChainId1000State;
import me.ahoo.cosid.jdbc.state.SegmentChainId100State;
import me.ahoo.cosid.jdbc.state.SegmentChainIdState;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Threads;
import me.ahoo.cosid.segment.SegmentChainId;
import org.openjdk.jmh.annotations.*;

/**
* @author ahoo wang
*/
@State(Scope.Benchmark)
public class MySqlChainIdBenchmark {

@Benchmark
public long atomicLong_baseline(JdkIdState jdkIdState) {
return jdkIdState.jdkId.generate();
}
@Param({"1", "100", "1000"})
private int step;

@Benchmark
@Threads(2)
public long step_1(SegmentChainIdState segmentChainIdState) {
return segmentChainIdState.segmentId.generate();
}
@Benchmark
public long step_100(SegmentChainId100State segmentChainId100State) {
return segmentChainId100State.segmentId.generate();
SegmentChainId segmentChainId;

@Setup
public void setup() {
segmentChainId = DataSourceFactory.INSTANCE.createSegmentChainId(step);
}

@Benchmark
public long step_1000(SegmentChainId1000State segmentChainId1000State) {
return segmentChainId1000State.segmentId.generate();
public long generate() {
return segmentChainId.generate();
}

}
27 changes: 14 additions & 13 deletions cosid-jdbc/src/jmh/java/me/ahoo/cosid/jdbc/MySqlIdBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@

package me.ahoo.cosid.jdbc;

import me.ahoo.cosid.jdbc.state.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Threads;
import me.ahoo.cosid.segment.SegmentId;
import org.openjdk.jmh.annotations.*;

/**
* @author ahoo wang
*/
@State(Scope.Benchmark)
public class MySqlIdBenchmark {

@Benchmark
@Threads(2)
public long step_1(SegmentIdState segmentIdState) {
return segmentIdState.segmentId.generate();
}
@Benchmark
public long step_100(SegmentId100State segmentId100State) {
return segmentId100State.segmentId.generate();
@Param({"1", "100", "1000"})
private int step;

SegmentId segmentId;

@Setup
public void setup() {
segmentId = DataSourceFactory.INSTANCE.createSegmentId(step);
}

@Benchmark
public long step_1000(SegmentId1000State segmentId1000State) {
return segmentId1000State.segmentId.generate();
public long generate() {
return segmentId.generate();
}

}
33 changes: 0 additions & 33 deletions cosid-jdbc/src/jmh/java/me/ahoo/cosid/jdbc/state/JdkIdState.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f6173ed

Please sign in to comment.