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

Fix benchmark

parent 02def1d6
Pipeline #21316 passed with stages
in 52 seconds
......@@ -97,7 +97,7 @@ func (box *BallotBox) Put(ballot *Ballot) error {
}
// Tally ballots
func (box *BallotBox) Tally(serverID UniqueID) *Tally {
func (box *BallotBox) Tally() *Tally {
box.Lock()
defer box.Unlock()
......
......@@ -243,7 +243,7 @@ func (election *Election) shouldTally() bool {
func (election *Election) Tally() *Tally {
election.Lock()
defer election.Unlock()
return election.ballotBox.Tally(election.ServerID)
return election.ballotBox.Tally()
}
// HandleTally handles the tallies received from servers
......
......@@ -10,11 +10,11 @@ import (
/////////////////////
///Setup functions///
/////////////////////
func makeBallots(votecount int, servercount int) [][]*Ballot {
ballots := make([][]*Ballot, votecount)
for i := 0; i < votecount; i++ {
ballots[i] = make([]*Ballot, servercount)
}
func makeBallots(votecount int, servercount int) []map[UniqueID]*Ballot {
ballots := make([]map[UniqueID]*Ballot, votecount)
// for i := 0; i < votecount; i++ {
// ballots[i] = make([]*Ballot, servercount)
// }
return ballots
}
func setupVote(votecount int) []*big.Int {
......@@ -25,32 +25,42 @@ func setupVote(votecount int) []*big.Int {
return votes
}
func createAllBallots(votes []*big.Int, servercount int, reqserver int, ballots [][]*Ballot) [][]*Ballot {
func createAllBallots(votes []*big.Int, servercount int, reqserver int, xs []*big.Int, ballots []map[UniqueID]*Ballot) []map[UniqueID]*Ballot {
for votenum := 0; votenum < len(votes); votenum++ {
for servernum := 0; servernum < servercount; servernum++ {
ballots[votenum] = CreateBallots(reqserver, servercount, votes[votenum])
ballots[votenum] = CreateBallots(reqserver, xs, votes[votenum])
}
}
return ballots
}
func createXS(n int) []*big.Int {
xs := make([]*big.Int, n)
for i := 1; i <= n; i++ {
xs[i-1] = big.NewInt(int64(i))
}
return xs
}
///////////////////////
///Client benchmarks///
///////////////////////
var result [][]*Ballot
var result []map[UniqueID]*Ballot
func benchmarkBallots(votecount, serverCount, reqServer int, b *testing.B) {
var r [][]*Ballot
var r []map[UniqueID]*Ballot
for i := 0; i < b.N; i++ {
//Setup
b.StopTimer()
ballots := makeBallots(votecount, serverCount)
votes := setupVote(votecount)
xs := createXS(serverCount)
//Actual benchmark
b.StartTimer()
r = createAllBallots(votes, serverCount, reqServer, ballots)
r = createAllBallots(votes, serverCount, reqServer, xs, ballots)
}
result = r
}
......@@ -81,13 +91,15 @@ 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))
box := NewBallotBox(big.NewInt(1), common.DefaultParams())
id := UniqueID("1")
for i := 0; i < votecount; i++ {
box.Put(CreateBallots(reqServer, serverCount, big.NewInt(1))[0])
_ = box.Put(CreateBallots(reqServer, createXS(serverCount), big.NewInt(1))[id])
}
//Actual benchmark
b.StartTimer()
box.Tally(box.ID)
box.Tally()
}
}
......
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