Commit 02def1d6 authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Merge

parents 4d50bfc5 ce15bfe7
Pipeline #21313 failed with stages
in 49 seconds
......@@ -6,7 +6,7 @@ import (
"testing"
)
func TestBallot(t *testing.T) {
func TestBallotZero(t *testing.T) {
params := common.DefaultParams()
ballots := CreateBallots(5, []*big.Int{
big.NewInt(1),
......@@ -20,8 +20,11 @@ func TestBallot(t *testing.T) {
t.Errorf("Failed to verify ballot %s\n", i)
}
}
}
ballots = CreateBallots(5, []*big.Int{
func TestBallotOne(t *testing.T) {
params := common.DefaultParams()
ballots := CreateBallots(5, []*big.Int{
big.NewInt(1),
big.NewInt(2),
big.NewInt(3),
......
package election
import (
"bsc-shamir/crypto/common"
"crypto/rand"
"math"
"math/big"
"testing"
)
......@@ -10,7 +10,7 @@ import (
/////////////////////
///Setup functions///
/////////////////////
func setupBallots(votecount int, servercount int) [][]*Ballot {
func makeBallots(votecount int, servercount int) [][]*Ballot {
ballots := make([][]*Ballot, votecount)
for i := 0; i < votecount; i++ {
ballots[i] = make([]*Ballot, servercount)
......@@ -40,16 +40,12 @@ func createAllBallots(votes []*big.Int, servercount int, reqserver int, ballots
var result [][]*Ballot
func benchmarkBallotsnm(voteCount, serverCount int, b *testing.B) {
reqServer := int(math.Ceil(float64(serverCount) / 2))
benchmarkBallotsnmo(voteCount, serverCount, reqServer, b)
}
func benchmarkBallotsnmo(votecount, serverCount, reqServer int, b *testing.B) {
func benchmarkBallots(votecount, serverCount, reqServer int, b *testing.B) {
var r [][]*Ballot
for i := 0; i < b.N; i++ {
//Setup
b.StopTimer()
ballots := setupBallots(votecount, serverCount)
ballots := makeBallots(votecount, serverCount)
votes := setupVote(votecount)
//Actual benchmark
......@@ -61,27 +57,42 @@ func benchmarkBallotsnmo(votecount, serverCount, reqServer int, b *testing.B) {
//Variable n
func BenchmarkBallotsServer(b *testing.B) {
b.Run("9 of 9 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 9, 9, b) })
b.Run("9 of 11 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 11, 9, b) })
b.Run("9 of 13 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 13, 9, b) })
b.Run("9 of 15 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 15, 9, b) })
b.Run("9 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 9, b) })
}
//Should just be linear
func BenchmarkBallotsVotes(b *testing.B) {
b.Run("3 servers", func(b *testing.B) { benchmarkBallotsnm(100, 5, b) })
b.Run("5 servers", func(b *testing.B) { benchmarkBallotsnm(1000, 5, b) })
b.Run("7 servers", func(b *testing.B) { benchmarkBallotsnm(10000, 5, b) })
b.Run("9 servers", func(b *testing.B) { benchmarkBallotsnm(100000, 5, b) })
b.Run("11 servers", func(b *testing.B) { benchmarkBallotsnm(1000000, 5, b) })
b.Run("9 of 9 servers", func(b *testing.B) { benchmarkBallots(1, 9, 9, b) })
b.Run("9 of 11 servers", func(b *testing.B) { benchmarkBallots(1, 11, 9, b) })
b.Run("9 of 13 servers", func(b *testing.B) { benchmarkBallots(1, 13, 9, b) })
b.Run("9 of 15 servers", func(b *testing.B) { benchmarkBallots(1, 15, 9, b) })
b.Run("9 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 9, b) })
}
//Variable t
func BenchmarkBallotsTrusted(b *testing.B) {
b.Run(" 9 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 9, b) })
b.Run("11 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 11, b) })
b.Run("13 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 13, b) })
b.Run("15 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 15, b) })
b.Run("17 of 17 servers", func(b *testing.B) { benchmarkBallotsnmo(1, 17, 17, b) })
b.Run(" 9 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 9, b) })
b.Run("11 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 11, b) })
b.Run("13 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 13, b) })
b.Run("15 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 15, b) })
b.Run("17 of 17 servers", func(b *testing.B) { benchmarkBallots(1, 17, 17, b) })
}
///////////////////////
///Server benchmarks///
///////////////////////
func benchmarkServer(votecount, serverCount, reqServer int, b *testing.B) {
for i := 0; i < b.N; i++ {
//Setup
b.StopTimer()
box := NewBallotBox(common.DefaultParams(), big.NewInt(1))
for i := 0; i < votecount; i++ {
box.Put(CreateBallots(reqServer, serverCount, big.NewInt(1))[0])
}
//Actual benchmark
b.StartTimer()
box.Tally(box.ID)
}
}
func BenchmarkServerBallot(b *testing.B) {
b.Run("10 Votes", func(b *testing.B) { benchmarkServer(10, 5, 3, b) })
b.Run("100 Votes", func(b *testing.B) { benchmarkServer(100, 5, 3, b) })
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment