First commit Go counter service
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package txlog
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"migadu_counters/internal/counting"
|
||||
"migadu_counters/internal/domains"
|
||||
)
|
||||
|
||||
const cdbPath = "../../test_files/rspamd_domains_db.cdb"
|
||||
|
||||
func BenchmarkReview_Open(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
db, err := domains.Open(cdbPath)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func benchLookup(b *testing.B, dom string) {
|
||||
db, err := domains.Open(cdbPath)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := db.Lookup(dom); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReview_LookupSmall(b *testing.B) { benchLookup(b, "yagolivas.com") }
|
||||
func BenchmarkReview_LookupHuge(b *testing.B) { benchLookup(b, "boxmailhere.com") }
|
||||
|
||||
func BenchmarkReview_InRequestHuge(b *testing.B) {
|
||||
db, err := domains.Open(cdbPath)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
p := &counting.Planner{Lookup: db, Now: time.Now}
|
||||
l := New(io.Discard, "text", nil)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
plan, err := p.PlanIn("t", "s@gmail.com", "someone@boxmailhere.com", false)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
out := &counting.Outcome{Plan: plan}
|
||||
for _, inc := range plan.Increments {
|
||||
out.Results = append(out.Results, counting.Result{Increment: inc, Count: 1})
|
||||
}
|
||||
l.Outcome(out, nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user