优化代码

This commit is contained in:
刘祥超
2022-01-10 15:38:53 +08:00
parent 344de90bff
commit 488430bbef
2 changed files with 23 additions and 1 deletions

View File

@@ -63,7 +63,11 @@ func (this *List) Remove(itemId int64) {
func (this *List) GC(timestamp int64, callback func(itemId int64)) {
this.locker.Lock()
itemMap := this.gcItems(timestamp)
var itemMap = this.gcItems(timestamp)
if len(itemMap) == 0 {
this.locker.Unlock()
return
}
this.locker.Unlock()
if callback != nil {

View File

@@ -165,3 +165,21 @@ func Benchmark_Map_Uint64(b *testing.B) {
}
}
}
func BenchmarkList_GC(b *testing.B) {
runtime.GOMAXPROCS(1)
var lists = []*List{}
for i := 0; i < 100; i++ {
lists = append(lists, NewList())
}
var timestamp = time.Now().Unix()
for i := 0; i < b.N; i++ {
for _, list := range lists {
list.GC(timestamp, nil)
}
}
}