-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement immediate mutex ringlist for LFU and LRU
- Loading branch information
Showing
10 changed files
with
598 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package evcache_test | ||
|
||
import ( | ||
"errors" | ||
"sync/atomic" | ||
"testing" | ||
|
||
"github.com/mgnsk/evcache/v3" | ||
) | ||
|
||
func BenchmarkFetchAndEvictParallel(b *testing.B) { | ||
b.StopTimer() | ||
|
||
c := evcache.New[uint64, int](0) | ||
index := uint64(0) | ||
errFetch := errors.New("error fetching") | ||
|
||
b.ReportAllocs() | ||
b.StartTimer() | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
if idx := atomic.AddUint64(&index, 1); idx%2 == 0 { | ||
_, _ = c.Fetch(0, 0, func() (int, error) { | ||
if idx%4 == 0 { | ||
return 0, errFetch | ||
} | ||
return 0, nil | ||
}) | ||
} else { | ||
c.Evict(0) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkFetchExists(b *testing.B) { | ||
b.StopTimer() | ||
|
||
c := evcache.New[uint64, int](0) | ||
c.LoadOrStore(0, 0, 0) | ||
|
||
b.ReportAllocs() | ||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, _ = c.Fetch(0, 0, func() (int, error) { | ||
panic("unexpected fetch callback") | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkFetchNotExists(b *testing.B) { | ||
b.StopTimer() | ||
|
||
c := evcache.New[int, int](0) | ||
|
||
b.ReportAllocs() | ||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, _ = c.Fetch(i, 0, func() (int, error) { | ||
return 0, nil | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/mgnsk/evcache/v3 | ||
|
||
go 1.21 | ||
|
||
require github.com/mgnsk/ringlist v0.0.0-20231025190742-1f621b925911 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/mgnsk/ringlist v0.0.0-20231025190742-1f621b925911 h1:/RUn/noOFPYcnnlsXmdmHSvKBp5gwQ5OnlNX9bRgeZE= | ||
github.com/mgnsk/ringlist v0.0.0-20231025190742-1f621b925911/go.mod h1:fyW9CbxFtYtWazjV96eJt4r+B2ABDRu3/rXQOxxTjLE= |
Oops, something went wrong.