go-twig/string_benchmark_test.go
semihalev f1add2d820 Implement efficient LRU eviction strategy for attribute cache
- 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>
2025-03-11 14:20:47 +03:00

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)
}
}