mirror of
https://github.com/semihalev/twig.git
synced 2026-03-14 13:55:46 +01:00
- Added tracking of last access time and access count to cache entries - Implemented eviction policy to remove least recently/frequently used entries - Cache now removes 10% of entries when the cache is full, prioritizing by usage - Added benchmarks and tests to verify eviction strategy - Fixed the previously ineffective eviction strategy - Improved cache efficiency for applications with many diverse object types 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package twig
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkWriteStringDirect(b *testing.B) {
|
|
buf := NewStringBuffer()
|
|
defer buf.Release()
|
|
longStr := "This is a test string for benchmarking the write performance of direct byte slice conversion"
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
buf.buf.Reset()
|
|
buf.buf.Write([]byte(longStr))
|
|
}
|
|
}
|
|
|
|
func BenchmarkWriteStringOptimized(b *testing.B) {
|
|
buf := NewStringBuffer()
|
|
defer buf.Release()
|
|
longStr := "This is a test string for benchmarking the write performance of optimized string writing"
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
buf.buf.Reset()
|
|
WriteString(&buf.buf, longStr)
|
|
}
|
|
}
|
|
|
|
func BenchmarkWriteStringDirect_Discard(b *testing.B) {
|
|
longStr := "This is a test string for benchmarking the write performance of direct byte slice conversion"
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ioutil.Discard.Write([]byte(longStr))
|
|
}
|
|
}
|
|
|
|
func BenchmarkWriteStringOptimized_Discard(b *testing.B) {
|
|
longStr := "This is a test string for benchmarking the write performance of optimized string writing"
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
WriteString(ioutil.Discard, longStr)
|
|
}
|
|
}
|