Subject: Re: bug#23772: 24.5; (format "%s" INTEGER) is slow

From: Eli Zaretskii <[email-masked]>
Date: Wed, 15 Jun 2016 17:59:28 +0300

> From: [email-masked]
> Date: Wed, 15 Jun 2016 20:40:04 +0900
> 
> (benchmark-run-compiled 100000 (format "%s" 0))
> =>(1.134 12 0.09000000000000119)
> (benchmark-run-compiled 100000 (format "%d" 0))
> =>(0.571 6 0.05500000000000016)
> (benchmark-run-compiled 100000 (format "%s" (format "%d" 0)))
> =>(0.652 13 0.12200000000000033)

Why is that a problem?  %d is passed to sprintf, so it's very fast; %s
whose argument is a string or a symbol is also fast, because it just
copies characters.  But %s with an argument that is neither a string
nor a symbol is implemented via a call to prin1-to-string, which is
more expensive because it produces a string representation of an
arbitrary Lisp object.  This is consistent with your results.

IOW, if you know the argument is an integer, and you care about
performance, don't use %s.