From 015b6346c61afaa7b4ae938658982239084044ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Moyne?= Date: Fri, 1 Nov 2024 16:37:10 -0700 Subject: [PATCH] Optimization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jean-Noël Moyne --- cli/bench_command.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cli/bench_command.go b/cli/bench_command.go index 00edf852..8d019fde 100644 --- a/cli/bench_command.go +++ b/cli/bench_command.go @@ -62,6 +62,7 @@ type benchCmd struct { fetchTimeout bool multiSubject bool multiSubjectMax int + multisubjectFormat string deDuplication bool deDuplicationWindow time.Duration ack bool @@ -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 @@ -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() @@ -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() @@ -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"