5 ms·
It seems easy to hit some implementation wart that makes performance abysmal - it's hard to believe that a JVM targeted language would be 20x times slower. Case
by pvg 17y ago
It seems easy to hit some implementation wart that makes performance abysmal - it's hard to believe that a JVM targeted language would be 20x times slower. Case in point - I tried the benchmark with a bigger input - the performance ratio between the 'fast' implementations remained the same. Incredibly, though, the CL implementation took nearly 2 minutes to construct the input string, something that is essentially instant in the Clojure version.
time sbcl --noinform --load palindromes.lisp --eval "(progn (big-test) (quit))"
30000 X ' amanaplanacanalpanama '
fast :
Evaluation took:
0.197 seconds of real time
0.191206 seconds of total run time (0.186952 user, 0.004254 system)
[ Run times consist of 0.006 seconds GC time, and 0.186 seconds non-GC time. ]
96.95% CPU
471,342,768 processor cycles
13,802,832 bytes consed
real 1m55.551s
user 1m51.954s
sys 0m0.778s
- lispm 17y agoBecause 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...