1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
package imap_benchmarks
import (
"context"
"flag"
"net"
"github.com/ProtonMail/gluon/benchmarks/gluon_bench/benchmark"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
)
var statusCallCountFlag = flag.Uint("imap-status-count", 1000, "Number of times to call status.")
type Status struct {
*stateTracker
}
func NewStatus() benchmark.Benchmark {
return NewIMAPBenchmarkRunner(&Status{stateTracker: newStateTracker()})
}
func (*Status) Name() string {
return "imap-status"
}
func (s *Status) Setup(ctx context.Context, addr net.Addr) error {
return WithClient(addr, func(cl *client.Client) error {
if _, err := s.createAndFillRandomMBox(cl); err != nil {
return err
}
return nil
})
}
func (s *Status) TearDown(ctx context.Context, addr net.Addr) error {
return s.cleanupWithAddr(addr)
}
func (s *Status) Run(ctx context.Context, addr net.Addr) error {
RunParallelClientsWithMailbox(addr, s.MBoxes[0], *fetchReadOnly, func(cl *client.Client, index uint) {
for i := uint(0); i < *statusCallCountFlag; i++ {
_, err := cl.Status(s.MBoxes[0], []imap.StatusItem{imap.StatusRecent, imap.StatusMessages, imap.StatusRecent, imap.StatusUnseen, imap.StatusUidNext, imap.StatusUidValidity})
if err != nil {
panic(err)
}
}
})
return nil
}
func init() {
benchmark.RegisterBenchmark(NewStatus())
}
|