4 ms·
Because the CL code to create the string is completely inefficient. It starts that he prints a string with format, using a format directive. Instead of (FORMAT
by lispm 17y ago
Because the CL code to create the string is completely inefficient. It starts that he prints a string with format, using a format directive. Instead of (FORMAT s "~a" string) use (write-string string s). Also, if the result string length is known, one can just allocate a result string and copy the source string repeatedly into the result string...
- pvg 17y agoIt's clear that it's inefficient and I'm no expert in either CL or FORMAT but it's not just inefficient, it's staggeringly inefficient. 2 minutes to make a few hundred k string on a 2+ghz CPU is hard to fathom, even if one assumes the method is imperfect, generates piles of garbage, etc, etc. It'd be interesting if someone could explain how this actually happens.
- lispm 17y agoI'd say it's a performance bug. Replacing (format stream "~a" string) with (format stream string) gets rid of the problem. LispWorks has no performance problem with both forms, though. The reason is the SBCL pretty printer. If *pretty-print* is NIL, then both forms run fast in SBCL...