Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to replace the accumulator from Vector with VectorBuilder #157

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@ And, so look at this [example](https://github.com/tkrs/fluflu/tree/master/module
Encoder

```
[info] Benchmark Mode Cnt Score Error Units
[info] MessagePackerBenchmark.encodeCirceAST thrpt 20 128408.501 ± 1866.924 ops/s
[info] MessagePackerBenchmark.encodeInt10 thrpt 20 315999.334 ± 4285.059 ops/s
[info] MessagePackerBenchmark.encodeInt30 thrpt 20 143539.468 ± 13205.880 ops/s
[info] MessagePackerBenchmark.encodeLong10 thrpt 20 343151.509 ± 19161.044 ops/s
[info] MessagePackerBenchmark.encodeLong30 thrpt 20 145687.290 ± 5606.780 ops/s
[info] MessagePackerBenchmark.encodeNested thrpt 20 102871.196 ± 1771.029 ops/s
[info] MessagePackerBenchmark.encodeString1000_30 thrpt 20 10593.208 ± 96.932 ops/s
[info] MessagePackerBenchmark.encodeString1000_30_multibyte thrpt 20 2395.656 ± 28.052 ops/s
[info] MessagePackerBenchmark.encodeString100_10 thrpt 20 239773.304 ± 5713.490 ops/s
[info] MessagePackerBenchmark.encodeString100_30 thrpt 20 105076.870 ± 1324.373 ops/s
[info] Benchmark Mode Cnt Score Error Units
[info] MessagePackerBenchmark.encodeCirceAST thrpt 20 133167.141 ± 2550.616 ops/s
[info] MessagePackerBenchmark.encodeInt10 thrpt 20 370109.732 ± 9878.608 ops/s
[info] MessagePackerBenchmark.encodeInt30 thrpt 20 143915.592 ± 29259.983 ops/s
[info] MessagePackerBenchmark.encodeLong10 thrpt 20 340296.568 ± 5333.504 ops/s
[info] MessagePackerBenchmark.encodeLong30 thrpt 20 153223.090 ± 2857.427 ops/s
[info] MessagePackerBenchmark.encodeNested thrpt 20 103858.391 ± 2043.339 ops/s
[info] MessagePackerBenchmark.encodeString1000_30 thrpt 20 10661.082 ± 181.357 ops/s
[info] MessagePackerBenchmark.encodeString1000_30_multibyte thrpt 20 2340.150 ± 51.082 ops/s
[info] MessagePackerBenchmark.encodeString100_10 thrpt 20 253301.605 ± 6416.145 ops/s
[info] MessagePackerBenchmark.encodeString100_30 thrpt 20 107762.022 ± 2849.293 ops/s
```

Decoder

```
[info] Benchmark Mode Cnt Score Error Units
[info] MessageUnpackerBenchmark.decodeCirceAST thrpt 20 118432.943 ± 1295.806 ops/s
[info] MessageUnpackerBenchmark.decodeInt10 thrpt 20 261754.469 ± 3832.825 ops/s
[info] MessageUnpackerBenchmark.decodeInt30 thrpt 20 114688.456 ± 2408.395 ops/s
[info] MessageUnpackerBenchmark.decodeLong10 thrpt 20 110070.005 ± 1526.381 ops/s
[info] MessageUnpackerBenchmark.decodeLong30 thrpt 20 41417.811 ± 1033.903 ops/s
[info] MessageUnpackerBenchmark.decodeNested thrpt 20 103433.867 ± 2209.280 ops/s
[info] MessageUnpackerBenchmark.decodeString1000_30 thrpt 20 33895.083 ± 402.245 ops/s
[info] MessageUnpackerBenchmark.decodeString1000_30_multibyte thrpt 20 5183.450 ± 67.308 ops/s
[info] MessageUnpackerBenchmark.decodeString100_10 thrpt 20 214975.326 ± 4839.443 ops/s
[info] MessageUnpackerBenchmark.decodeString100_30 thrpt 20 92710.917 ± 1210.946 ops/s
[info] Benchmark Mode Cnt Score Error Units
[info] MessageUnpackerBenchmark.decodeCirceAST thrpt 20 128765.305 ± 7875.374 ops/s
[info] MessageUnpackerBenchmark.decodeInt10 thrpt 20 292540.216 ± 8016.177 ops/s
[info] MessageUnpackerBenchmark.decodeInt30 thrpt 20 130384.440 ± 5428.657 ops/s
[info] MessageUnpackerBenchmark.decodeLong10 thrpt 20 116669.811 ± 2423.805 ops/s
[info] MessageUnpackerBenchmark.decodeLong30 thrpt 20 42903.651 ± 1197.532 ops/s
[info] MessageUnpackerBenchmark.decodeNested thrpt 20 105284.983 ± 2737.642 ops/s
[info] MessageUnpackerBenchmark.decodeString1000_30 thrpt 20 35019.191 ± 808.341 ops/s
[info] MessageUnpackerBenchmark.decodeString1000_30_multibyte thrpt 20 5053.968 ± 49.745 ops/s
[info] MessageUnpackerBenchmark.decodeString100_10 thrpt 20 221799.362 ± 4139.716 ops/s
[info] MessageUnpackerBenchmark.decodeString100_30 thrpt 20 96945.679 ± 3381.020 ops/s
```

## LICENSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.openjdk.jmh.annotations._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 10, time = 3)
@Warmup(iterations = 10, time = 1)
@Measurement(iterations = 10, time = 1)
@OutputTimeUnit(TimeUnit.SECONDS)
@Fork(2)
class MessageUnpackerBenchmark extends TestData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.msgpack.core.MessagePack.UnpackerConfig
import org.msgpack.core.{MessageUnpacker => MUnpacker}

import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Try

object MessageUnpacker {
Expand Down Expand Up @@ -90,24 +91,26 @@ final class MessageUnpacker(src: ByteBuffer, config: UnpackerConfig) {
}

private def unpackList(limit: Int, buffer: MUnpacker): Json = {
@tailrec def loop(i: Int, acc: Vector[Json]): Vector[Json] =
if (i == limit) acc else loop(i + 1, acc :+ unpack0(buffer))
Json.fromValues(loop(0, Vector.empty))
@tailrec def loop(i: Int, acc: mutable.Builder[Json, Vector[Json]]): Vector[Json] =
if (i == limit) acc.result() else loop(i + 1, acc += unpack0(buffer))
Json.fromValues(loop(0, Vector.newBuilder[Json]))
}

private def unpackMap(size: Int, buffer: MUnpacker): Json = {
@tailrec def loop(i: Int, acc: Vector[(String, Json)]): Vector[(String, Json)] =
if (i == 0) acc
@tailrec def loop(
i: Int,
acc: mutable.Builder[(String, Json), Vector[(String, Json)]]): Vector[(String, Json)] =
if (i == 0) acc.result()
else {
val kj = unpack0(buffer)
val vj = unpack0(buffer)
kj.asString match {
case Some(key) =>
loop(i - 1, acc :+ (key -> vj))
loop(i - 1, acc += (key -> vj))
case None =>
throw new Exception(s"Unpack map was failed. current position: $i")
}
}
Json.fromFields(loop(size, Vector.empty))
Json.fromFields(loop(size, Vector.newBuilder))
}
}