From 853b19fb022ecfddb45d65759cf992062bbfb030 Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Tue, 7 Jun 2022 11:29:27 +0800 Subject: [PATCH] del --- byte_cache/byte_cache.go | 36 ----------------------------------- byte_cache/byte_cache_test.go | 28 --------------------------- 2 files changed, 64 deletions(-) delete mode 100644 byte_cache/byte_cache.go delete mode 100644 byte_cache/byte_cache_test.go diff --git a/byte_cache/byte_cache.go b/byte_cache/byte_cache.go deleted file mode 100644 index 44954d6..0000000 --- a/byte_cache/byte_cache.go +++ /dev/null @@ -1,36 +0,0 @@ -package bytecache - -type BytePool struct { - c chan []byte - w int - wcap int -} - -func NewBytePool(poolSize, size, cap int) *BytePool { - return &BytePool{ - c: make(chan []byte, poolSize), - w: size, - wcap: cap, - } -} - -func (bp *BytePool) Get() (b []byte) { - select { - case b = <-bp.c: - default: - if bp.wcap > 0 { - b = make([]byte, bp.w, bp.wcap) - } else { - b = make([]byte, bp.w) - } - } - - return -} - -func (bp *BytePool) Put(b []byte) { - select { - case bp.c <- b: - default: - } -} diff --git a/byte_cache/byte_cache_test.go b/byte_cache/byte_cache_test.go deleted file mode 100644 index 444e25b..0000000 --- a/byte_cache/byte_cache_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package bytecache - -import "testing" - -func TestByteCache(t *testing.T) { - bp := NewBytePool(512, 1024, 1024) - buffer := bp.Get() - defer bp.Put(buffer) - - t.Log(len(buffer)) -} - -func BenchmarkByteCache(b *testing.B) { - bp := NewBytePool(512, 1024, 1024) - b.Run("aaaaa", func(b *testing.B) { - for i := 0; i < b.N; i++ { - bp.Put(bp.Get()) - } - }) - - b.Run("bbbb", func(b *testing.B) { - for i := 0; i < b.N; i++ { - a := make([]byte, 1024) - - a[0] = 1 - } - }) -}