``` 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
@ -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 |
||||
|
} |
@ -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 |
||||
|
) |