Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from 0bsnetwork/merge-0162
Merge 0.16.2 (m/t)
- Loading branch information
Showing
254 changed files
with
8,275 additions
and
3,781 deletions.
There are no files selected for viewing
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
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
75 changes: 75 additions & 0 deletions
75
benchmark/src/test/scala/com/zbsnetwork/serialization/protobuf/ProtoBufBenchmark.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.zbsnetwork.serialization.protobuf | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import com.zbsnetwork.account.PublicKeyAccount | ||
import com.zbsnetwork.common.state.ByteStr | ||
import com.zbsnetwork.common.utils.Base58 | ||
import com.zbsnetwork.protobuf.transaction.PBTransactions | ||
import com.zbsnetwork.transaction.Proofs | ||
import com.zbsnetwork.transaction.transfer.MassTransferTransaction | ||
import com.zbsnetwork.transaction.transfer.MassTransferTransaction.Transfer | ||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Threads(1) | ||
@Fork(1) | ||
@Warmup(iterations = 10) | ||
@Measurement(iterations = 10) | ||
class ProtoBufBenchmark { | ||
|
||
@Benchmark | ||
def serializeMassTransferPB_test(bh: Blackhole): Unit = { | ||
val vanillaTx = { | ||
val transfers = MassTransferTransaction | ||
.parseTransfersList( | ||
List(Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 100000000L), Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 200000000L))) | ||
.right | ||
.get | ||
|
||
MassTransferTransaction | ||
.create( | ||
None, | ||
PublicKeyAccount.fromBase58String("FM5ojNqW7e9cZ9zhPYGkpSP1Pcd8Z3e3MNKYVS5pGJ8Z").right.get, | ||
transfers, | ||
1518091313964L, | ||
200000, | ||
Base58.decode("59QuUcqP6p").get, | ||
Proofs(Seq(ByteStr.decodeBase58("FXMNu3ecy5zBjn9b69VtpuYRwxjCbxdkZ3xZpLzB8ZeFDvcgTkmEDrD29wtGYRPtyLS3LPYrL2d5UM6TpFBMUGQ").get)) | ||
) | ||
.right | ||
.get | ||
} | ||
|
||
val tx = PBTransactions.protobuf(vanillaTx) | ||
bh.consume(tx.toByteArray) | ||
} | ||
|
||
@Benchmark | ||
def serializeMassTransferVanilla_test(bh: Blackhole): Unit = { | ||
val vanillaTx = { | ||
val transfers = MassTransferTransaction | ||
.parseTransfersList( | ||
List(Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 100000000L), Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 200000000L))) | ||
.right | ||
.get | ||
|
||
MassTransferTransaction | ||
.create( | ||
None, | ||
PublicKeyAccount.fromBase58String("FM5ojNqW7e9cZ9zhPYGkpSP1Pcd8Z3e3MNKYVS5pGJ8Z").right.get, | ||
transfers, | ||
1518091313964L, | ||
200000, | ||
Base58.decode("59QuUcqP6p").get, | ||
Proofs(Seq(ByteStr.decodeBase58("FXMNu3ecy5zBjn9b69VtpuYRwxjCbxdkZ3xZpLzB8ZeFDvcgTkmEDrD29wtGYRPtyLS3LPYrL2d5UM6TpFBMUGQ").get)) | ||
) | ||
.right | ||
.get | ||
} | ||
|
||
bh.consume(vanillaTx.bytes()) | ||
} | ||
} |
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
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
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
10 changes: 9 additions & 1 deletion
10
common/shared/src/main/scala/com/zbsnetwork/common/utils/package.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package com.zbsnetwork.common | ||
import scala.util.{Failure, Success, Try} | ||
|
||
package object utils { | ||
|
||
implicit class EitherExt2[A, B](ei: Either[A, B]) { | ||
|
||
def explicitGet(): B = ei match { | ||
case Left(value) => throw new Exception(value.toString) | ||
case Right(value) => value | ||
} | ||
} | ||
|
||
def foldToTry: Try[B] = { | ||
ei.fold( | ||
left => Failure(new Exception(left.toString)), | ||
right => Success(right) | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.