Professional Documents
Culture Documents
Didier Verna
Abstract
Contrary to popular belief, Lisp code can be very efcient today: it can run as fast as equivalent C code
Safety Levels
formance.
We also
Data Structures
in both languages.
Introduction
processing.
faster
than C.
formance in Lisp:
Compilers
terpreted language, there are very good and ecient compilers out there, that can deliver not
only byte-code, but also
Static Typing
2.1
Experimental Conditions
The Algorithms
Our experiments are based on 4 very simple algorithms: pixel assignment (initializing an image with a
constant value), and pixel addition / multiplication /
division (lling a destination image with the addition
/ multiplication / division of every pixel from a source
image by a constant value). These algorithms, while
very simple, are pertinent because they involve the
fundamental atomic operations of image processing:
pixel access and arithmetic processing.
etc.
For
Listing 1:
float
thor's website .
In the remainder of this paper, we consider
800 800
2.2
The
bian
The Protocol
benchmarks
Gnu/Linux
2.4.27-2-686
have
0.29
0.29
0.48
0.47
0.48
0.46
0.58
1.93
system
generated
running
on
De-
packaged
In order to
etc.),
the
cheaper) arithmetics.
First attempt at
Lisp Code
C compiler, gcc
It should be
4 version
cvs 19c.
noted however that the performance gain from inlining is almost negligible. Indeed, the cost of the func-
is shown in listing 2.
i.e.
float
images.
Figure 1 presents the execution times for all C algorithms on both integer and oating point,
800 800
1 http://www.lrde.epita.fr/~didier/comp/research/
2 http://www.debian.org
3 http://gcc.gnu.org
The
besides
the
in-
4 http://www.cons.org/cmucl
Arrays al-
malloc'ed
or
calloc'ed
make-array.
multidimensional.
to
array-dimension
array and you know that this array will only contain
the
setf.
aref
The function
and assignation
Unsurprisingly,
dotimes
:element-type keyword
make-array like this:
is a
for
tion
language construct in C.
cluded).
declarations issued.
To understand why we are getting this poor performance, one has to realize that our Lisp code is
typed :
un-
to,
array-dimension
For
on the function
val,
but noth-
number.
Lisp Code
two arrays of
single-float
parameter.
The
(*)
specica-
tion indicates that the arrays are 1D, but the actual
size is unknown (at compile-time). 2D arrays would
have been described with
Typing
5.1
single-float
(* *)
for instance.
Typing mechanisms
5.2
Ob jects Representation
time.
forced
types can
own type.
Rather, the
5.3
The rst example deals with the way Lisp objects are
58701478:
90:
93:
96:
98:
9A: L0 :
9D: L1 :
A2:
A4:
A9:
AC:
AF:
B2:
B4:
B6:
Listing 4:
.ENTRY FOO()
POP
DWORD PTR [ EBP 8]
LEA
ESP, [ EBP 32]
XOR
EAX, EAX
JMP
L1
ADD
EAX, 4
CMP
EAX, 400
JL
L0
MOV
EDX, #x2800000B
MOV
ECX, [ EBP 8]
MOV
EAX, [ EBP 4]
ADD
ECX, 2
MOV
ESP, EBP
MOV
EBP, EAX
JMP
ECX
Disassembly of a dotimes loop
aref
5.5
Optimization
func-
of dereferencing pointers.
be interested in optimizing.
5.4
Immediate Objects
safety
speed
that is, objects that are small enough to be representable without indirection (on a single memory
by means of
basis, by means of
instance:
loop.
Lisp compiler will treat type declarations as assertions and trigger an error when values are not of the
time.
machine integers.
tions
etc..
need
C.
to be es-
optimizations.
0.29
0.29
0.29
6.1
Loop Arithmetics
0.48
0.48
0.47
0.46
0.48
0.48
0.46
0.45
0.58
1.80
1.93
1.72
dotimes
dotimes
in listing 3.
rst
for the
exactly
index.
6.2
Arithmetic results
This
Type Inference
For instance,
5.
smart.
infer
Unfortunately (and
Conclusion
better
We should
References
[1] Richard J. Fateman,
ane
oating-point
etc..
This
K.
Willcock,
processing
21(1):2662,
March 1995.
and
Perspectives
Common-Lisp.
Downloadable ver-
Object-Oriented Programming in
a Programmer's Guide to Clos.
Addison-Wesley, 1989.
DiFast
at
Lisp community.
rectly
in
Rettig.
http://openmap.bbn.com/~kanderso/
performance/postscript/lispfloat.ps.
sion
Common-Lisp:
Duane
Kevin A. Broughan,
and
Cmu-CL. In ACM Conference on Lisp and Functional Programming, pages 235246, 1992. Downloadable version at
~ram/pub/lfp.ps.
http://www-2.cs.cmu.edu/
able version at
architectures, and also to dig into each compiler's specic optimization options to see if performance can be
improved even more.
From a medium-level point of view, benchmarking
very simple algorithms was necessary to isolate the
http://www.cs.cmu.edu/Groups/
AI/html/cltl/cltl2.html.
[6] Henry S. Warren.
Wesley Professional,
Hacker's Delight.
hackersdelight.org.
July 2002.
Addison
http://www.