Commit f193d2e3 authored by Thomas Hoffmann's avatar Thomas Hoffmann
Browse files

Cleaned benchmark

parent 4d98753c
Pipeline #21402 failed with stages
in 58 seconds
......@@ -17,13 +17,7 @@ import (
/////////////////////
///Setup functions///
/////////////////////
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 {
votes := make([]*big.Int, votecount)
for i := 0; i < votecount; i++ {
......@@ -32,7 +26,8 @@ func setupVote(votecount int) []*big.Int {
return votes
}
func createAllBallots(votes []*big.Int, servercount int, reqserver int, xs []*big.Int, ballots []map[UniqueID]*Ballot) []map[UniqueID]*Ballot {
func createAllBallots(votes []*big.Int, servercount int, reqserver int, xs []*big.Int) []map[UniqueID]*Ballot {
ballots := make([]map[UniqueID]*Ballot, len(votes))
for votenum := 0; votenum < len(votes); votenum++ {
for servernum := 0; servernum < servercount; servernum++ {
ballots[votenum] = CreateBallots(reqserver, xs, votes[votenum])
......@@ -57,23 +52,21 @@ var result []map[UniqueID]*Ballot
func benchmarkBallots(votecount, serverCount, reqServer int, b *testing.B) {
var r []map[UniqueID]*Ballot
//Setup
b.StopTimer()
votes := setupVote(votecount)
xs := createXS(serverCount)
b.StartTimer()
//Actual benchmark
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, xs, ballots)
r = createAllBallots(votes, serverCount, reqServer, xs)
}
result = r
}
//Variable n
func BenchmarkBallotsServer(b *testing.B) {
log.SetOutput(ioutil.Discard)
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) })
......@@ -83,6 +76,7 @@ func BenchmarkBallotsServer(b *testing.B) {
//Variable t
func BenchmarkBallotsTrusted(b *testing.B) {
log.SetOutput(ioutil.Discard)
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) })
......@@ -95,22 +89,23 @@ func BenchmarkBallotsTrusted(b *testing.B) {
///////////////////////////////
func benchmarkTally(votecount, serverCount, reqServer int, b *testing.B) {
for i := 0; i < b.N; i++ {
//Setup
b.StopTimer()
box := NewBallotBox(big.NewInt(1), common.DefaultParams())
//Setup
b.StopTimer()
box := NewBallotBox(big.NewInt(1), common.DefaultParams())
id := UniqueID("1")
for i := 0; i < votecount; i++ {
_ = box.Put(CreateBallots(reqServer, createXS(serverCount), big.NewInt(1))[id])
}
//Actual benchmark
b.StartTimer()
id := UniqueID("1")
for i := 0; i < votecount; i++ {
_ = box.Put(CreateBallots(reqServer, createXS(serverCount), big.NewInt(1))[id])
}
//Actual benchmark
b.StartTimer()
for i := 0; i < b.N; i++ {
box.Tally()
}
}
func BenchmarkBallotVote(b *testing.B) {
log.SetOutput(ioutil.Discard)
b.Run("10 Votes", func(b *testing.B) { benchmarkTally(10, 5, 3, b) })
b.Run("100 Votes", func(b *testing.B) { benchmarkTally(100, 5, 3, b) })
b.Run("1000 Votes", func(b *testing.B) { benchmarkTally(1000, 5, 3, b) })
......@@ -118,6 +113,7 @@ func BenchmarkBallotVote(b *testing.B) {
b.Run("100000 Votes", func(b *testing.B) { benchmarkTally(100000, 5, 3, b) })
}
func BenchmarkBallotServer(b *testing.B) {
log.SetOutput(ioutil.Discard)
b.Run("9 of 9 servers", func(b *testing.B) { benchmarkTally(100, 9, 9, b) })
b.Run("9 of 11 servers", func(b *testing.B) { benchmarkTally(100, 11, 9, b) })
b.Run("9 of 13 servers", func(b *testing.B) { benchmarkTally(100, 13, 9, b) })
......@@ -145,7 +141,7 @@ func benchmarkCombine(votecount, serverCount, reqServer int, b *testing.B) {
b.StopTimer()
votes := setupVote(votecount)
xs := createXS(serverCount)
ballots := createAllBallots(votes, serverCount, reqServer, xs, makeBallots(votecount, serverCount))
ballots := createAllBallots(votes, serverCount, reqServer, xs)
ballotBoxes := make([]*BallotBox, serverCount)
tallyBoxes := make([]*TallyBox, serverCount)
for i := 0; i < serverCount; i++ {
......
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