From ab0ee97c182180ea830d78f0dc2bfe7c17bcad5c Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Thu, 19 Mar 2015 13:47:24 -0700 Subject: [PATCH] ValidatorSet copy benchmark --- state/validator_set_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/state/validator_set_test.go b/state/validator_set_test.go index 3c9b3d943..0153c1440 100644 --- a/state/validator_set_test.go +++ b/state/validator_set_test.go @@ -40,3 +40,23 @@ func TestCopy(t *testing.T) { t.Fatalf("ValidatorSet copy had wrong hash. Orig: %X, Copy: %X", vsetHash, vsetCopyHash) } } + +func BenchmarkValidatorSetCopy(b *testing.B) { + b.StopTimer() + vset := NewValidatorSet([]*Validator{}) + for i := 0; i < 1000; i++ { + privAccount := account.GenPrivAccount() + val := &Validator{ + Address: privAccount.Address, + PubKey: privAccount.PubKey.(account.PubKeyEd25519), + } + if !vset.Add(val) { + panic("Failde to add validator") + } + } + b.StartTimer() + + for i := 0; i < b.N; i++ { + vset.Copy() + } +}