| 300 | } |
| 301 | |
| 302 | func BenchmarkMemoryList(b *testing.B) { |
| 303 | var list = caches.NewMemoryList() |
| 304 | err := list.Init() |
| 305 | if err != nil { |
| 306 | b.Fatal(err) |
| 307 | } |
| 308 | for i := 0; i < 1_000_000; i++ { |
| 309 | _ = list.Add(stringutil.Md5(types.String(i)), &caches.Item{ |
| 310 | Key: "a1", |
| 311 | ExpiresAt: time.Now().Unix() + 3600, |
| 312 | HeaderSize: 1024, |
| 313 | }) |
| 314 | } |
| 315 | |
| 316 | b.ResetTimer() |
| 317 | |
| 318 | b.RunParallel(func(pb *testing.PB) { |
| 319 | for pb.Next() { |
| 320 | _, _, _ = list.Exist(types.String("a" + types.String(rands.Int(1, 10000)))) |
| 321 | _ = list.Add("a"+types.String(rands.Int(1, 100000)), &caches.Item{}) |
| 322 | _, _ = list.Purge(1000, func(hash string) error { |
| 323 | return nil |
| 324 | }) |
| 325 | } |
| 326 | }) |
| 327 | } |