(b *testing.B)
| 55 | } |
| 56 | |
| 57 | func BenchmarkMemoryWriter_Capacity(b *testing.B) { |
| 58 | b.ReportAllocs() |
| 59 | |
| 60 | var storage = caches.NewMemoryStorage(&serverconfigs.HTTPCachePolicy{ |
| 61 | Id: 0, |
| 62 | IsOn: false, |
| 63 | Name: "", |
| 64 | Description: "", |
| 65 | Capacity: &shared.SizeCapacity{ |
| 66 | Count: 8, |
| 67 | Unit: shared.SizeCapacityUnitGB, |
| 68 | }, |
| 69 | }, nil) |
| 70 | initErr := storage.Init() |
| 71 | if initErr != nil { |
| 72 | b.Fatal(initErr) |
| 73 | } |
| 74 | |
| 75 | const size = 1 << 20 |
| 76 | const chunkSize = 16 << 10 |
| 77 | var data = bytes.Repeat([]byte{'A'}, chunkSize) |
| 78 | |
| 79 | b.ResetTimer() |
| 80 | |
| 81 | b.RunParallel(func(pb *testing.PB) { |
| 82 | for pb.Next() { |
| 83 | var writer = caches.NewMemoryWriter(storage, "a"+strconv.Itoa(rand.Int()), time.Now().Unix()+3600, 200, false, size, 1<<30, func(valueItem *caches.MemoryItem) { |
| 84 | }) |
| 85 | |
| 86 | for i := 0; i < size/chunkSize; i++ { |
| 87 | _, err := writer.Write(data) |
| 88 | if err != nil { |
| 89 | b.Fatal(err) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | err := writer.Close() |
| 94 | if err != nil { |
| 95 | b.Fatal(err) |
| 96 | } |
| 97 | } |
| 98 | }) |
| 99 | } |
| 100 | |
| 101 | func BenchmarkMemoryWriter_Capacity_Disabled(b *testing.B) { |
| 102 | b.ReportAllocs() |
nothing calls this directly
no test coverage detected