Skip to content

Commit

Permalink
Fix jmh
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemyev Vyacheslav committed Nov 14, 2023
1 parent 7c97e66 commit 1188b4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ CONTENT.md

#JMH
benchmarks.jar

# MacOS
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ import com.viartemev.thewhiterabbit.channel.ConfirmChannel
import com.viartemev.thewhiterabbit.channel.createConfirmChannel
import com.viartemev.thewhiterabbit.publisher.ConfirmPublisher
import com.viartemev.thewhiterabbit.publisher.OutboundMessage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Fork
import org.openjdk.jmh.annotations.Level
import org.openjdk.jmh.annotations.Measurement
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.OutputTimeUnit
import org.openjdk.jmh.annotations.Param
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 org.openjdk.jmh.annotations.Warmup
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit

Expand All @@ -46,7 +36,7 @@ open class ConfirmPublisherBenchmark {
channel = connection.createConfirmChannel()
channel.queueDeclare(testQueueName, false, false, false, mapOf())
publisher = channel.publisher()
messages = (1..numberOfMessages).map { createMessage() }
messages = (1..numberOfMessages).map { OutboundMessage("", testQueueName, MessageProperties.MINIMAL_BASIC, "") }
}

@TearDown(Level.Iteration)
Expand All @@ -60,16 +50,13 @@ open class ConfirmPublisherBenchmark {
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
fun avgTimeSendWithPublishConfirm(blackhole: Blackhole) = runBlocking {
blackhole.consume(publisher.publishWithConfirmAsync(messages = messages).awaitAll())
blackhole.consume(messages.map { async(Dispatchers.IO) { publisher.publishWithConfirm(it) } }.awaitAll())
}

@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
fun throughputSendWithPublishConfirm(blackhole: Blackhole) = runBlocking {
blackhole.consume(publisher.publishWithConfirmAsync(messages = messages).awaitAll())
blackhole.consume(messages.map { async(Dispatchers.IO) { publisher.publishWithConfirm(it) } }.awaitAll())
}


private fun createMessage(): OutboundMessage = OutboundMessage("", testQueueName, MessageProperties.MINIMAL_BASIC, "")
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ buildscript {
plugins {
id("jacoco")
id "com.github.johnrengelman.shadow" version "8.1.1"
id "org.jetbrains.dokka" version "1.9.10"
id "java-library"
}

configure(allprojects) { project ->
Expand Down

0 comments on commit 1188b4f

Please sign in to comment.