@@ -7,21 +7,11 @@ import com.viartemev.thewhiterabbit.channel.ConfirmChannel
7
7
import com.viartemev.thewhiterabbit.channel.createConfirmChannel
8
8
import com.viartemev.thewhiterabbit.publisher.ConfirmPublisher
9
9
import com.viartemev.thewhiterabbit.publisher.OutboundMessage
10
+ import kotlinx.coroutines.Dispatchers
11
+ import kotlinx.coroutines.async
10
12
import kotlinx.coroutines.awaitAll
11
13
import kotlinx.coroutines.runBlocking
12
- import org.openjdk.jmh.annotations.Benchmark
13
- import org.openjdk.jmh.annotations.BenchmarkMode
14
- import org.openjdk.jmh.annotations.Fork
15
- import org.openjdk.jmh.annotations.Level
16
- import org.openjdk.jmh.annotations.Measurement
17
- import org.openjdk.jmh.annotations.Mode
18
- import org.openjdk.jmh.annotations.OutputTimeUnit
19
- import org.openjdk.jmh.annotations.Param
20
- import org.openjdk.jmh.annotations.Scope
21
- import org.openjdk.jmh.annotations.Setup
22
- import org.openjdk.jmh.annotations.State
23
- import org.openjdk.jmh.annotations.TearDown
24
- import org.openjdk.jmh.annotations.Warmup
14
+ import org.openjdk.jmh.annotations.*
25
15
import org.openjdk.jmh.infra.Blackhole
26
16
import java.util.concurrent.TimeUnit
27
17
@@ -46,7 +36,7 @@ open class ConfirmPublisherBenchmark {
46
36
channel = connection.createConfirmChannel()
47
37
channel.queueDeclare(testQueueName, false , false , false , mapOf ())
48
38
publisher = channel.publisher()
49
- messages = (1 .. numberOfMessages).map { createMessage( ) }
39
+ messages = (1 .. numberOfMessages).map { OutboundMessage ( " " , testQueueName, MessageProperties . MINIMAL_BASIC , " " ) }
50
40
}
51
41
52
42
@TearDown(Level .Iteration )
@@ -60,16 +50,13 @@ open class ConfirmPublisherBenchmark {
60
50
@BenchmarkMode(Mode .AverageTime )
61
51
@OutputTimeUnit(TimeUnit .MICROSECONDS )
62
52
fun avgTimeSendWithPublishConfirm (blackhole : Blackhole ) = runBlocking {
63
- blackhole.consume(publisher.publishWithConfirmAsync(messages = messages) .awaitAll())
53
+ blackhole.consume(messages.map { async( Dispatchers . IO ) { publisher.publishWithConfirm(it) } } .awaitAll())
64
54
}
65
55
66
56
@Benchmark
67
57
@BenchmarkMode(Mode .Throughput )
68
58
@OutputTimeUnit(TimeUnit .MICROSECONDS )
69
59
fun throughputSendWithPublishConfirm (blackhole : Blackhole ) = runBlocking {
70
- blackhole.consume(publisher.publishWithConfirmAsync(messages = messages) .awaitAll())
60
+ blackhole.consume(messages.map { async( Dispatchers . IO ) { publisher.publishWithConfirm(it) } } .awaitAll())
71
61
}
72
-
73
-
74
- private fun createMessage (): OutboundMessage = OutboundMessage (" " , testQueueName, MessageProperties .MINIMAL_BASIC , " " )
75
62
}
0 commit comments