Skip to content

Commit

Permalink
benchmark test for user validator
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 20, 2019
1 parent 8d09d74 commit 1531642
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions proxy/vmess/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
. "v2ray.com/core/proxy/vmess"
)

func toAccount(a *Account) protocol.Account {
account, err := a.AsAccount()
common.Must(err)
return account
}

func TestUserValidator(t *testing.T) {
hasher := protocol.DefaultIDHash
v := NewTimedUserValidator(hasher)
defer common.Close(v)

toAccount := func(a *Account) protocol.Account {
account, err := a.AsAccount()
common.Must(err)
return account
}

id := uuid.New()
user := &protocol.MemoryUser{
Email: "test",
Expand Down Expand Up @@ -88,3 +88,23 @@ func TestUserValidator(t *testing.T) {
t.Error("remove user twice")
}
}

func BenchmarkUserValidator(b *testing.B) {
for i := 0; i < b.N; i++ {
hasher := protocol.DefaultIDHash
v := NewTimedUserValidator(hasher)

for j := 0; j < 1500; j++ {
id := uuid.New()
v.Add(&protocol.MemoryUser{
Email: "test",
Account: toAccount(&Account{
Id: id.String(),
AlterId: 16,
}),
})
}

common.Close(v)
}
}

0 comments on commit 1531642

Please sign in to comment.