improoved benchmark

This commit is contained in:
kirari04 2024-06-11 16:53:29 +02:00
parent 6026c4fd53
commit 61e4d45430
No known key found for this signature in database
GPG Key ID: 373DF6E799D233FD

View File

@ -7,9 +7,25 @@ import (
"testing"
)
func BenchmarkRateLimitSyncMapInt64(b *testing.B) {
ipTableSyncMapInt64 = IpTableSyncMapInt64{} // Reset the table
func BenchmarkRateLimitLockMapInt64(b *testing.B) {
go InitRateLimit()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimit(w, r, &ProxyEndpoint{RateLimiting: 10})
})
request := httptest.NewRequest("GET", "/", nil)
request.RemoteAddr = "192.168.1.1:1234"
b.ResetTimer()
for i := 0; i < b.N; i++ {
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, request)
}
}
func BenchmarkRateLimitSyncMapInt64(b *testing.B) {
go InitRateLimitSyncMapInt64()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimitSyncMapInt64(w, r, &ProxyEndpoint{RateLimiting: 10})
})
@ -26,8 +42,7 @@ func BenchmarkRateLimitSyncMapInt64(b *testing.B) {
}
func BenchmarkRateLimitSyncMapAtomicInt64(b *testing.B) {
ipTableSyncMapAtomicInt64 = IpTableSyncMapAtomicInt64{} // Reset the table
go InitRateLimitSyncMapAtomicInt64()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimitSyncMapAtomicInt64(w, r, &ProxyEndpoint{RateLimiting: 10})
})
@ -43,9 +58,31 @@ func BenchmarkRateLimitSyncMapAtomicInt64(b *testing.B) {
}
}
func BenchmarkRateLimitSyncMapInt64Concurrent(b *testing.B) {
ipTableSyncMapInt64 = IpTableSyncMapInt64{} // Reset the table
func BenchmarkRateLimitLockMapInt64Concurrent(b *testing.B) {
go InitRateLimit()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimit(w, r, &ProxyEndpoint{RateLimiting: 10})
})
request := httptest.NewRequest("GET", "/", nil)
request.RemoteAddr = "192.168.1.1:1234"
b.ResetTimer()
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
wg.Add(1)
go func() {
defer wg.Done()
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, request)
}()
}
wg.Wait()
}
func BenchmarkRateLimitSyncMapInt64Concurrent(b *testing.B) {
go InitRateLimitSyncMapInt64()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimitSyncMapInt64(w, r, &ProxyEndpoint{RateLimiting: 10})
})
@ -68,8 +105,7 @@ func BenchmarkRateLimitSyncMapInt64Concurrent(b *testing.B) {
}
func BenchmarkRateLimitSyncMapAtomicInt64Concurrent(b *testing.B) {
ipTableSyncMapAtomicInt64 = IpTableSyncMapAtomicInt64{} // Reset the table
go InitRateLimitSyncMapAtomicInt64()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleRateLimitSyncMapAtomicInt64(w, r, &ProxyEndpoint{RateLimiting: 10})
})