Last active
March 28, 2016 09:15
-
-
Save mp911de/ff021322f7a60043ea1e to your computer and use it in GitHub Desktop.
Long Parsing Benchmark
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
# JMH 1.11.3 (released 74 days ago) | |
# VM version: JDK 1.8.0_71, VM 25.71-b15 | |
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/jre/bin/java | |
# VM options: -Dvisualvm.id=43580837207773 -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 | |
# Warmup: 5 iterations, 1 s each | |
# Measurement: 5 iterations, 1 s each | |
# Timeout: 2 s per iteration | |
# Threads: 1 thread, will synchronize iterations | |
# Benchmark mode: Average time, time/op | |
# Benchmark: com.lambdaworks.redis.protocol.LongParsingBenchmark.longProcessor | |
# Run progress: 0,00% complete, ETA 00:00:40 | |
# Fork: 1 of 1 | |
# Warmup Iteration 1: 10,127 ns/op | |
# Warmup Iteration 2: 9,633 ns/op | |
# Warmup Iteration 3: 9,699 ns/op | |
# Warmup Iteration 4: 10,514 ns/op | |
# Warmup Iteration 5: 9,516 ns/op | |
Iteration 1: 9,663 ns/op | |
Iteration 2: 9,947 ns/op | |
Iteration 3: 9,409 ns/op | |
Iteration 4: 9,757 ns/op | |
Iteration 5: 9,632 ns/op | |
Result "longProcessor": | |
9,682 ±(99.9%) 0,753 ns/op [Average] | |
(min, avg, max) = (9,409, 9,682, 9,947), stdev = 0,196 | |
CI (99.9%): [8,929, 10,434] (assumes normal distribution) | |
# JMH 1.11.3 (released 74 days ago) | |
# VM version: JDK 1.8.0_71, VM 25.71-b15 | |
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/jre/bin/java | |
# VM options: -Dvisualvm.id=43580837207773 -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 | |
# Warmup: 5 iterations, 1 s each | |
# Measurement: 5 iterations, 1 s each | |
# Timeout: 2 s per iteration | |
# Threads: 1 thread, will synchronize iterations | |
# Benchmark mode: Average time, time/op | |
# Benchmark: com.lambdaworks.redis.protocol.LongParsingBenchmark.parseLongFromByteBuf | |
# Run progress: 25,00% complete, ETA 00:00:31 | |
# Fork: 1 of 1 | |
# Warmup Iteration 1: 70,845 ns/op | |
# Warmup Iteration 2: 69,691 ns/op | |
# Warmup Iteration 3: 58,829 ns/op | |
# Warmup Iteration 4: 59,035 ns/op | |
# Warmup Iteration 5: 59,910 ns/op | |
Iteration 1: 62,801 ns/op | |
Iteration 2: 59,258 ns/op | |
Iteration 3: 60,079 ns/op | |
Iteration 4: 59,046 ns/op | |
Iteration 5: 65,334 ns/op | |
Result "parseLongFromByteBuf": | |
61,304 ±(99.9%) 10,416 ns/op [Average] | |
(min, avg, max) = (59,046, 61,304, 65,334), stdev = 2,705 | |
CI (99.9%): [50,887, 71,720] (assumes normal distribution) | |
# JMH 1.11.3 (released 74 days ago) | |
# VM version: JDK 1.8.0_71, VM 25.71-b15 | |
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/jre/bin/java | |
# VM options: -Dvisualvm.id=43580837207773 -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 | |
# Warmup: 5 iterations, 1 s each | |
# Measurement: 5 iterations, 1 s each | |
# Timeout: 2 s per iteration | |
# Threads: 1 thread, will synchronize iterations | |
# Benchmark mode: Average time, time/op | |
# Benchmark: com.lambdaworks.redis.protocol.LongParsingBenchmark.parseLongFromBytes | |
# Run progress: 50,00% complete, ETA 00:00:21 | |
# Fork: 1 of 1 | |
# Warmup Iteration 1: 49,833 ns/op | |
# Warmup Iteration 2: 42,756 ns/op | |
# Warmup Iteration 3: 45,776 ns/op | |
# Warmup Iteration 4: 40,484 ns/op | |
# Warmup Iteration 5: 43,504 ns/op | |
Iteration 1: 42,413 ns/op | |
Iteration 2: 41,737 ns/op | |
Iteration 3: 40,410 ns/op | |
Iteration 4: 40,052 ns/op | |
Iteration 5: 42,152 ns/op | |
Result "parseLongFromBytes": | |
41,353 ±(99.9%) 4,081 ns/op [Average] | |
(min, avg, max) = (40,052, 41,353, 42,413), stdev = 1,060 | |
CI (99.9%): [37,272, 45,434] (assumes normal distribution) | |
# JMH 1.11.3 (released 74 days ago) | |
# VM version: JDK 1.8.0_71, VM 25.71-b15 | |
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/jre/bin/java | |
# VM options: -Dvisualvm.id=43580837207773 -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 | |
# Warmup: 5 iterations, 1 s each | |
# Measurement: 5 iterations, 1 s each | |
# Timeout: 2 s per iteration | |
# Threads: 1 thread, will synchronize iterations | |
# Benchmark mode: Average time, time/op | |
# Benchmark: com.lambdaworks.redis.protocol.LongParsingBenchmark.parseLongFromString | |
# Run progress: 75,00% complete, ETA 00:00:10 | |
# Fork: 1 of 1 | |
# Warmup Iteration 1: 7,092 ns/op | |
# Warmup Iteration 2: 6,667 ns/op | |
# Warmup Iteration 3: 6,151 ns/op | |
# Warmup Iteration 4: 6,218 ns/op | |
# Warmup Iteration 5: 6,934 ns/op | |
Iteration 1: 6,677 ns/op | |
Iteration 2: 7,090 ns/op | |
Iteration 3: 6,745 ns/op | |
Iteration 4: 6,351 ns/op | |
Iteration 5: 6,225 ns/op | |
Result "parseLongFromString": | |
6,618 ±(99.9%) 1,318 ns/op [Average] | |
(min, avg, max) = (6,225, 6,618, 7,090), stdev = 0,342 | |
CI (99.9%): [5,300, 7,935] (assumes normal distribution) | |
# Run complete. Total time: 00:00:43 | |
Benchmark Mode Cnt Score Error Units | |
LongParsingBenchmark.longProcessor avgt 5 9,682 ± 0,753 ns/op | |
LongParsingBenchmark.parseLongFromByteBuf avgt 5 61,304 ± 10,416 ns/op | |
LongParsingBenchmark.parseLongFromBytes avgt 5 41,353 ± 4,081 ns/op | |
LongParsingBenchmark.parseLongFromString avgt 5 6,618 ± 1,318 ns/op |
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
package com.lambdaworks.redis.protocol; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import io.netty.buffer.ByteBuf; | |
import io.netty.buffer.Unpooled; | |
import io.netty.util.CharsetUtil; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
/** | |
* @author Mark Paluch | |
*/ | |
@State(Scope.Thread) | |
public class LongParsingBenchmark { | |
private final static byte[] FOURTY_TWO = "42".getBytes(); | |
private final static ByteBuf NUMBER = Unpooled.wrappedBuffer(FOURTY_TWO); | |
private final RedisStateMachine.ToLongProcessor toLongProcessor = new RedisStateMachine.ToLongProcessor(); | |
@Benchmark | |
public Long parseLongFromByteBuf() { | |
ByteBuf buf = NUMBER.duplicate(); | |
byte[] data = new byte[buf.readableBytes()]; | |
buf.readBytes(data); | |
return Long.parseLong(new String(data, CharsetUtil.US_ASCII)); | |
} | |
@Benchmark | |
public Long parseLongFromBytes() { | |
return Long.parseLong(new String(FOURTY_TWO, CharsetUtil.US_ASCII)); | |
} | |
@Benchmark | |
public Long parseLongFromString() { | |
return Long.parseLong("43"); | |
} | |
@Benchmark | |
public long longProcessor() { | |
ByteBuf buf = NUMBER.duplicate(); | |
toLongProcessor.result = 0; | |
toLongProcessor.first = true; | |
buf.forEachByte(toLongProcessor); | |
if (!toLongProcessor.negative) { | |
return -toLongProcessor.result; | |
} | |
return toLongProcessor.result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment