You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.2 KiB

  1. package types
  2. import (
  3. "testing"
  4. "time"
  5. amino "github.com/tendermint/go-amino"
  6. "github.com/tendermint/tendermint/crypto/ed25519"
  7. cmn "github.com/tendermint/tendermint/libs/common"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. func BenchmarkRoundStateDeepCopy(b *testing.B) {
  11. b.StopTimer()
  12. // Random validators
  13. nval, ntxs := 100, 100
  14. vset, _ := types.RandValidatorSet(nval, 1)
  15. precommits := make([]*types.Vote, nval)
  16. blockID := types.BlockID{
  17. Hash: cmn.RandBytes(20),
  18. PartsHeader: types.PartSetHeader{
  19. Hash: cmn.RandBytes(20),
  20. },
  21. }
  22. sig := ed25519.SignatureEd25519{}
  23. for i := 0; i < nval; i++ {
  24. precommits[i] = &types.Vote{
  25. ValidatorAddress: types.Address(cmn.RandBytes(20)),
  26. Timestamp: time.Now(),
  27. BlockID: blockID,
  28. Signature: sig,
  29. }
  30. }
  31. txs := make([]types.Tx, ntxs)
  32. for i := 0; i < ntxs; i++ {
  33. txs[i] = cmn.RandBytes(100)
  34. }
  35. // Random block
  36. block := &types.Block{
  37. Header: types.Header{
  38. ChainID: cmn.RandStr(12),
  39. Time: time.Now(),
  40. LastBlockID: blockID,
  41. LastCommitHash: cmn.RandBytes(20),
  42. DataHash: cmn.RandBytes(20),
  43. ValidatorsHash: cmn.RandBytes(20),
  44. ConsensusHash: cmn.RandBytes(20),
  45. AppHash: cmn.RandBytes(20),
  46. LastResultsHash: cmn.RandBytes(20),
  47. EvidenceHash: cmn.RandBytes(20),
  48. },
  49. Data: types.Data{
  50. Txs: txs,
  51. },
  52. Evidence: types.EvidenceData{},
  53. LastCommit: &types.Commit{
  54. BlockID: blockID,
  55. Precommits: precommits,
  56. },
  57. }
  58. parts := block.MakePartSet(4096)
  59. // Random Proposal
  60. proposal := &types.Proposal{
  61. Timestamp: time.Now(),
  62. BlockPartsHeader: types.PartSetHeader{
  63. Hash: cmn.RandBytes(20),
  64. },
  65. POLBlockID: blockID,
  66. Signature: sig,
  67. }
  68. // Random HeightVoteSet
  69. // TODO: hvs :=
  70. rs := &RoundState{
  71. StartTime: time.Now(),
  72. CommitTime: time.Now(),
  73. Validators: vset,
  74. Proposal: proposal,
  75. ProposalBlock: block,
  76. ProposalBlockParts: parts,
  77. LockedBlock: block,
  78. LockedBlockParts: parts,
  79. ValidBlock: block,
  80. ValidBlockParts: parts,
  81. Votes: nil, // TODO
  82. LastCommit: nil, // TODO
  83. LastValidators: vset,
  84. }
  85. b.StartTimer()
  86. for i := 0; i < b.N; i++ {
  87. amino.DeepCopy(rs)
  88. }
  89. }