Skip to content

Commit

Permalink
fix: jitter return in duration instead of float64
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 14, 2023
1 parent a6e3c68 commit 0fbe4fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func MeasureLatency(address string, numPackets int, packetTimeout time.Duration,
return averageLatency, nil
}

func MeasureJitter(address string, numPackets int, packetTimeout time.Duration, logger *zap.Logger) (float64, error) {
func MeasureJitter(address string, numPackets int, packetTimeout time.Duration, logger *zap.Logger) (time.Duration, error) {
var totalJitter time.Duration
prevLatency := time.Duration(0)

for i := 0; i < numPackets; i++ {
latency, err := MeasureLatency(address, numPackets, packetTimeout, logger)
latency, err := MeasureLatency(address, 1, packetTimeout, logger)
if err != nil {
logger.Error("Error measuring latency:", zap.Error(err))
continue
Expand All @@ -61,7 +61,7 @@ func MeasureJitter(address string, numPackets int, packetTimeout time.Duration,
prevLatency = latency
}

averageJitter := float64(totalJitter) / float64(numPackets-1)
averageJitter := totalJitter / time.Duration(numPackets-1)
return averageJitter, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/goping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var pingCmd = &cobra.Command{
return err
}

logger.Info("Jitter", zap.Float64("jitter", jitter))
logger.Info("Jitter", zap.Duration("jitter", jitter))

if flagsPing.quiet {
fmt.Print(jitter)
Expand Down

0 comments on commit 0fbe4fc

Please sign in to comment.