mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-10 04:20:27 +08:00
优化代码
This commit is contained in:
@@ -63,7 +63,11 @@ func (this *List) Remove(itemId int64) {
|
|||||||
|
|
||||||
func (this *List) GC(timestamp int64, callback func(itemId int64)) {
|
func (this *List) GC(timestamp int64, callback func(itemId int64)) {
|
||||||
this.locker.Lock()
|
this.locker.Lock()
|
||||||
itemMap := this.gcItems(timestamp)
|
var itemMap = this.gcItems(timestamp)
|
||||||
|
if len(itemMap) == 0 {
|
||||||
|
this.locker.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
this.locker.Unlock()
|
this.locker.Unlock()
|
||||||
|
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user