Skip to content

Instantly share code, notes, and snippets.

@phuslu
phuslu / bench_test.go
Last active January 23, 2024 10:24
fast parse DeletionTimestamp from pod
package bench
import (
"testing"
)
func BenchmarkParseDeletionTimestamp(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = ParseDeletionTimestamp(data)
@phuslu
phuslu / cachingmap.go
Last active March 25, 2024 01:19
双缓冲实现无锁map,读取性能和GC友好度最好,一致性较差,写入延迟一般建议设置为分钟级。 https://twitter.com/phuslu/status/1745276311235395708
type CachingMap[K comparable, V any] struct {
// double buffering mechanism
index int64
maps [2]map[K]V
// write queue
queue chan struct {
key K
value V
}