From ffd0e9625da4db1671b8af46ea9b10e23224048b Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Thu, 23 May 2019 17:00:29 -0700 Subject: [PATCH] Optimize basic sampler --- sampler.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sampler.go b/sampler.go index 2360f0d..7b0923e 100644 --- a/sampler.go +++ b/sampler.go @@ -46,8 +46,12 @@ type BasicSampler struct { // Sample implements the Sampler interface. func (s *BasicSampler) Sample(lvl Level) bool { + n := s.N + if n == 1 { + return true + } c := atomic.AddUint32(&s.counter, 1) - return c%s.N == s.N-1 + return c%n == 1 } // BurstSampler lets Burst events pass per Period then pass the decision to