Skip to content

Commit 7b9ab71

Browse files
committed
minor code improvements, proof size measurement
1 parent db6428c commit 7b9ab71

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/main/scala/scorex/crypto/benchmarks/BatchingBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object BatchingBenchmark extends App with TwoPartyTests {
103103
for (iteration <- 0 until(totalSize, step)) {
104104

105105
val converted = Modification.convert(mods.slice(i + iteration, i + iteration + step))
106-
var digest = oldProver.rootHash
106+
val digest = oldProver.rootHash
107107

108108

109109
val (oldProverTimeT, oldProofs: Seq[AVLModifyProof]) = time {

src/main/scala/scorex/crypto/benchmarks/BlockchainBench.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import scala.util.{Random, Try}
1616
trait BenchmarkCommons {
1717
val hf = new Blake2b256Unsafe()
1818

19-
val initElements = 5000000
19+
val initialSize = 5000000
2020

2121
val blocks = 90000
2222

@@ -33,11 +33,6 @@ trait TwoPartyCommons extends BenchmarkCommons with UpdateF[TreapValue] {
3333
cacheSize(1).
3434
open()
3535

36-
/*DBMaker
37-
.fileDB("/tmp/proofs")
38-
.closeOnJvmShutdown()
39-
.make()*/
40-
4136
lazy val proofsMap = db.openMap[Integer, Array[Byte]]("proofs")
4237

4338
def set(value: TreapValue): UpdateFunction = { oldOpt: Option[TreapValue] => Try(Some(oldOpt.getOrElse(value))) }
@@ -62,8 +57,8 @@ trait Initializing extends BenchmarkCommons {
6257
protected var keyCache: mutable.Buffer[hf.Digest] = mutable.Buffer()
6358

6459
def init(): Unit = {
65-
(0 until initElements - keyCacheSize).foreach(initStep)
66-
keyCache.appendAll(((initElements - keyCacheSize) until initElements).map(initStep))
60+
(0 until initialSize - keyCacheSize).foreach(initStep)
61+
keyCache.appendAll(((initialSize - keyCacheSize) until initialSize).map(initStep))
6762
afterInit()
6863
}
6964
}
@@ -79,7 +74,6 @@ class Prover extends TwoPartyCommons with Initializing {
7974
}
8075

8176
override protected def afterInit(): Unit = {
82-
//val rootVar = db.atomicVar("root", Serializer.BYTE_ARRAY).createOrOpen()
8377
setRoot(treeRoot)
8478
db.commit()
8579
}
@@ -102,7 +96,7 @@ class Prover extends TwoPartyCommons with Initializing {
10296

10397
//proofs generation
10498
def dumpProofs(blockNum: Int, proofs: Seq[AVLModifyProof]): Unit = {
105-
var idx = initElements + perBlock * blockNum
99+
var idx = initialSize + perBlock * blockNum
106100
proofs.foreach { proof =>
107101
proofsMap.put(idx, proof.bytes)
108102
idx = idx + 1
@@ -174,7 +168,7 @@ class Verifier extends TwoPartyCommons {
174168
lazy val initRoot = getRoot()
175169

176170
def loadProofs(blockNum: Int): Seq[AVLModifyProof] = {
177-
(initElements + perBlock * blockNum) until (initElements + perBlock * (blockNum + 1)) map { idx =>
171+
(initialSize + perBlock * blockNum) until (initialSize + perBlock * (blockNum + 1)) map { idx =>
178172
AVLModifyProof.parseBytes(proofsMap.get(idx)).get
179173
}
180174
}
@@ -301,12 +295,18 @@ trait BenchmarkLaunchers extends BenchmarkCommons {
301295
val sf = System.currentTimeMillis()
302296
val dsf = sf - sf0
303297
p.dumpProofs(blockNum, proofs, root, modKeys)
304-
println(s"block #$blockNum, prover: $dsf")
305-
298+
println(s"block #$blockNum, " +
299+
s"prover time: $dsf, " +
300+
s"state size before: ${initialSize + (blockNum - 1)*additionsInBlock}, " +
301+
s"state size after: ${initialSize + blockNum * additionsInBlock} " +
302+
s"proofs size: ${proofs.size}"
303+
)
304+
305+
/* todo: is regular GC needed?
306306
if (blockNum % 5000 == 4999) {
307307
System.gc()
308308
Thread.sleep(60000)
309-
}
309+
}*/
310310
}
311311
p.close()
312312
}

0 commit comments

Comments
 (0)