GNU bug report logs - #23772
24.5; (format "%s" INTEGER) is slow

Previous Next

Package: emacs;

Reported by: ynyaaa <at> gmail.com

Date: Wed, 15 Jun 2016 11:41:02 UTC

Severity: wishlist

Tags: notabug, wontfix

Found in version 24.5

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


Message #8 received at 23772 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: ynyaaa <at> gmail.com
Cc: 23772 <at> debbugs.gnu.org
Subject: Re: bug#23772: 24.5; (format "%s" INTEGER) is slow
Date: Wed, 15 Jun 2016 17:59:28 +0300
> From: ynyaaa <at> gmail.com
> 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.




This bug report was last modified 8 years and 147 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.