Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Noël Moyne <[email protected]>
  • Loading branch information
jnmoyne committed Nov 1, 2024
1 parent c0f7939 commit 015b634
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cli/bench_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type benchCmd struct {
fetchTimeout bool
multiSubject bool
multiSubjectMax int
multisubjectFormat string
deDuplication bool
deDuplicationWindow time.Duration
ack bool
Expand Down Expand Up @@ -453,9 +454,7 @@ func (c *benchCmd) getPublishSubject(number int) string {
if c.multiSubjectMax == 0 {
return c.subject + "." + strconv.Itoa(number)
} else {
maxDigits := len(strconv.Itoa(c.multiSubjectMax))
format := fmt.Sprintf("%%0%dd", maxDigits)
return c.subject + "." + fmt.Sprintf(format, number%c.multiSubjectMax)
return c.subject + "." + fmt.Sprintf(c.multisubjectFormat, number%c.multiSubjectMax)
}
} else {
return c.subject
Expand Down Expand Up @@ -1548,6 +1547,8 @@ func (c *benchCmd) coreNATSPublisher(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1577,6 +1578,8 @@ func (c *benchCmd) coreNATSRequester(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1612,6 +1615,8 @@ func (c *benchCmd) jsPublisher(nc *nats.Conn, progress *uiprogress.Bar, msg []by
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

if c.batchSize != 1 {
for i := 0; i < numMsg; {
state = "Publishing"
Expand Down

0 comments on commit 015b634

Please sign in to comment.