Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
77
backend/benchmarks/benchmark_test.go
Normal file
77
backend/benchmarks/benchmark_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/explorer/backend/api/track1"
|
||||
)
|
||||
|
||||
// BenchmarkInMemoryCache_Get benchmarks cache Get operations
|
||||
func BenchmarkInMemoryCache_Get(b *testing.B) {
|
||||
cache := track1.NewInMemoryCache()
|
||||
key := "bench-key"
|
||||
value := []byte("bench-value")
|
||||
cache.Set(key, value, 5*time.Minute)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _ = cache.Get(key)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkInMemoryCache_Set benchmarks cache Set operations
|
||||
func BenchmarkInMemoryCache_Set(b *testing.B) {
|
||||
cache := track1.NewInMemoryCache()
|
||||
key := "bench-key"
|
||||
value := []byte("bench-value")
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = cache.Set(key, value, 5*time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkInMemoryRateLimiter_Allow benchmarks rate limiter Allow operations
|
||||
func BenchmarkInMemoryRateLimiter_Allow(b *testing.B) {
|
||||
config := track1.RateLimitConfig{
|
||||
RequestsPerMinute: 1000,
|
||||
}
|
||||
limiter := track1.NewInMemoryRateLimiter(config)
|
||||
key := "bench-key"
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = limiter.Allow(key)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkCache_Concurrent benchmarks concurrent cache operations
|
||||
func BenchmarkCache_Concurrent(b *testing.B) {
|
||||
cache := track1.NewInMemoryCache()
|
||||
key := "bench-key"
|
||||
value := []byte("bench-value")
|
||||
cache.Set(key, value, 5*time.Minute)
|
||||
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
_, _ = cache.Get(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// BenchmarkRateLimiter_Concurrent benchmarks concurrent rate limiter operations
|
||||
func BenchmarkRateLimiter_Concurrent(b *testing.B) {
|
||||
config := track1.RateLimitConfig{
|
||||
RequestsPerMinute: 10000,
|
||||
}
|
||||
limiter := track1.NewInMemoryRateLimiter(config)
|
||||
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
key := "bench-key"
|
||||
for pb.Next() {
|
||||
_ = limiter.Allow(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user