Browse Source

Add treeinterface benchmarks

```
nCPU: 4, nLeafs: 10000
	asmtree.Add loop:	1m33.393613916s
	asmtree.AddBatch:	480.164271ms
	gravitontree.Add loop:	10.127451689s
	gravitontree.AddBatch:	141.29108ms
	arbo.Add loop:		1.16466211s
	arbo.AddBatch:		97.870759ms

nCPU: 8, nLeafs: 10000
	asmtree.Add loop:	24.538163095s
	asmtree.AddBatch:	194.14454ms
	gravitontree.Add loop:	6.150883978s
	gravitontree.AddBatch:	90.742666ms
	arbo.Add loop:		600.259558ms
	arbo.AddBatch:		50.440291ms

---

nCPU: 4, nLeafs: 500000
	asmtree.AddBatch:	24.95076993s
	gravitontree.AddBatch:	11.768588412s
	arbo.AddBatch:		23.360363426s

nCPU: 8, nLeafs: 500000
	asmtree.Add loop:	(not executed)
	asmtree.AddBatch:	14.363474201s
	gravitontree.Add loop:	8m45.300930089s
	gravitontree.AddBatch:	7.377581508s
	arbo.Add loop:  	2m0.229851504s
	arbo.AddBatch:  	8.759028338s
```
dependabot/npm_and_yarn/circom-examples/normalize-url-4.5.1
arnaucube 2 years ago
parent
commit
aa0d8728d8
6 changed files with 2266 additions and 4 deletions
  1. +1
    -1
      treeinterface/arbotree/go.mod
  2. +3
    -0
      treeinterface/arbotree/go.sum
  3. +2
    -3
      treeinterface/arbotree/wrapper.go
  4. +94
    -0
      treeinterface/benchmarks/bench_test.go
  5. +12
    -0
      treeinterface/benchmarks/go.mod
  6. +2154
    -0
      treeinterface/benchmarks/go.sum

+ 1
- 1
treeinterface/arbotree/go.mod

@ -5,7 +5,7 @@ go 1.16
// replace github.com/arnaucube/arbo => ../../../arbo
require (
github.com/arnaucube/arbo v0.0.0-20210518085706-03bb9f744792 // indirect
github.com/arnaucube/arbo v0.0.0-20210519105811-13378d338ef2 // indirect
github.com/iden3/go-merkletree v0.0.0-20210308143313-8b63ca866189
go.vocdoni.io/dvote v0.6.1-0.20210508104027-72380d23da7f
)

+ 3
- 0
treeinterface/arbotree/go.sum

@ -107,6 +107,8 @@ github.com/arnaucube/arbo v0.0.0-20210508150807-6dcbbdf4a51a h1:gBPYofXmm/ehWn07
github.com/arnaucube/arbo v0.0.0-20210508150807-6dcbbdf4a51a/go.mod h1:ZlejgAnqIb9ysj5z9Husdqant+3arJbac8CBStess/s=
github.com/arnaucube/arbo v0.0.0-20210518085706-03bb9f744792 h1:0lwF3FXiztk0Dh6wpdjYGczOtG5HAB8reIgeuHBuuqo=
github.com/arnaucube/arbo v0.0.0-20210518085706-03bb9f744792/go.mod h1:ZlejgAnqIb9ysj5z9Husdqant+3arJbac8CBStess/s=
github.com/arnaucube/arbo v0.0.0-20210519105811-13378d338ef2 h1:+FUT+aflOwwIa14uqMQmNdCt1pmfCQjEhnAb5tTVxZQ=
github.com/arnaucube/arbo v0.0.0-20210519105811-13378d338ef2/go.mod h1:ZlejgAnqIb9ysj5z9Husdqant+3arJbac8CBStess/s=
github.com/arnaucube/go-blindsecp256k1 v0.0.0-20210203222605-876755a714c3/go.mod h1:10oM1DQMpukFfSzNsjSQG2rE6UjoGsXT4iIxWIiVbu0=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
@ -1463,6 +1465,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca h1:Ld/zXl5t4+D69SiV4JoN7kkfvJdOWlPpfxrzxpLMoUk=
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8=

+ 2
- 3
treeinterface/arbotree/wrapper.go

@ -12,7 +12,7 @@ import (
"time"
"github.com/arnaucube/arbo"
"github.com/iden3/go-merkletree/db/pebble"
"github.com/iden3/go-merkletree/db/leveldb"
"go.vocdoni.io/dvote/censustree"
)
@ -24,11 +24,10 @@ type Tree struct {
func (t *Tree) Init(name, storageDir string) error {
dbDir := filepath.Join(storageDir, "arbotree.db."+strings.TrimSpace(name))
storage, err := pebble.NewPebbleStorage(dbDir, false) // TODO TMP
storage, err := leveldb.NewLevelDbStorage(dbDir, false) // TODO TMP
if err != nil {
return err
}
// storage := memory.NewMemoryStorage()
mt, err := arbo.NewTree(storage, 140, arbo.HashFunctionBlake2b) // TODO here the hash function would depend on the usage
if err != nil {

+ 94
- 0
treeinterface/benchmarks/bench_test.go

@ -0,0 +1,94 @@
package benchmarks
import (
"crypto/rand"
"fmt"
"runtime"
"testing"
"time"
"github.com/arnaucube/kesto/treeinterface/arbotree"
asmtree "github.com/p4u/asmt"
"go.vocdoni.io/dvote/censustree"
"go.vocdoni.io/dvote/censustree/gravitontree"
)
// func BenchmarkAddBatch(b *testing.B) {
func TestAddBatch(t *testing.T) {
nLeafs := 100_000
fmt.Printf("nCPU: %d, nLeafs: %d\n", runtime.NumCPU(), nLeafs)
// prepare inputs
var ks, vs [][]byte
for i := 0; i < nLeafs; i++ {
k := randomBytes(32)
v := randomBytes(32)
ks = append(ks, k)
vs = append(vs, v)
}
tree1 := &asmtree.Tree{}
benchmarkAdd(t, "asmtree", tree1, ks, vs)
tree1 = &asmtree.Tree{}
benchmarkAddBatch(t, "asmtree", tree1, ks, vs)
tree2 := &gravitontree.Tree{}
benchmarkAdd(t, "gravitontree", tree2, ks, vs)
tree2 = &gravitontree.Tree{}
benchmarkAddBatch(t, "gravitontree", tree2, ks, vs)
tree3 := &arbotree.Tree{}
benchmarkAdd(t, "arbo", tree3, ks, vs)
tree3 = &arbotree.Tree{}
benchmarkAddBatch(t, "arbo", tree3, ks, vs)
}
func benchmarkAdd(t *testing.T, name string, tree censustree.Tree, ks, vs [][]byte) {
storage := t.TempDir()
err := tree.Init("test1", storage)
if err != nil {
t.Fatal(err)
}
start := time.Now()
for i := 0; i < len(ks); i++ {
if err := tree.Add(ks[i], vs[i]); err != nil {
t.Fatal(err)
}
}
printRes(t, name+".Add loop", time.Since(start))
}
func benchmarkAddBatch(t *testing.T, name string, tree censustree.Tree, ks, vs [][]byte) {
storage := t.TempDir()
err := tree.Init("test1", storage)
if err != nil {
t.Fatal(err)
}
start := time.Now()
invalids, err := tree.AddBatch(ks, vs)
if err != nil {
t.Fatal(err)
}
if len(invalids) != 0 {
t.Fatal("len(invalids)!=0")
}
printRes(t, name+".AddBatch", time.Since(start))
}
func printRes(t *testing.T, name string, duration time.Duration) {
fmt.Printf(" %s: %s \n", name, duration)
}
func randomBytes(n int) []byte {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return b
}

+ 12
- 0
treeinterface/benchmarks/go.mod

@ -0,0 +1,12 @@
module github.com/arnaucube/kesto/treeinterface/benchmarks
go 1.16
replace github.com/arnaucube/kesto/treeinterface/arbotree => ../arbotree
require (
github.com/arnaucube/arbo v0.0.0-20210519105811-13378d338ef2
github.com/arnaucube/kesto/treeinterface/arbotree v0.0.0-20210518090017-aff9bcc18604
github.com/p4u/asmt v0.0.0-20210327173007-3e47da54b6b6
go.vocdoni.io/dvote v0.6.1-0.20210519145433-4b6da3324284
)

+ 2154
- 0
treeinterface/benchmarks/go.sum
File diff suppressed because it is too large
View File


Loading…
Cancel
Save