From: Samantha Skyler
Subject: Compile Question? (I'm not sure)
Date: 
Message-ID: <3fd88790.0206132052.7a1c1ca5@posting.google.com>
Hello all,

I'm doing some very computationally intensive stuff in lisp right now,
and I need some advice/help.

I need for this program to run as quickly as possible.

Right now, to run my program, I open up a terminal window (I'm using
Red Hat 7.3) and type

CLISP filename.lisp

And off it goes.

What I want to know is, 

1) Is there anyway I can compile my source code into something like an
executable file for Linux?

2) If I complied it, would it be any faster?

3) If so, what do I need to do to compile my source?

Thanks in advance.

-Samantha.

From: Christopher Browne
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <aebunt$5m9ol$2@ID-125932.news.dfncis.de>
In an attempt to throw the authorities off his trail, ··············@hotmail.com (Samantha Skyler) transmitted:
> Hello all,
>
> I'm doing some very computationally intensive stuff in lisp right now,
> and I need some advice/help.
>
> I need for this program to run as quickly as possible.
>
> Right now, to run my program, I open up a terminal window (I'm using
> Red Hat 7.3) and type
>
> CLISP filename.lisp
>
> And off it goes.
>
> What I want to know is, 
>
> 1) Is there anyway I can compile my source code into something like an
> executable file for Linux?
>
> 2) If I complied it, would it be any faster?
>
> 3) If so, what do I need to do to compile my source?

You should get a bit of a performance boost by bytecompiling the
program.

% clisp -c filename.lisp
  will generate filename.fas/filename.lib, and those should load and
  run more quickly than what you've got running now.

If that does not suffice, you should look into installing CMUCL, which
can compile to native code on IA-32.  With it, you would do:
] (compile-file "filename.lisp")
and find that it generates filename.x86f, which contains native code,
and which is quite likely to be a lot faster than CLISP was.
-- 
(concatenate 'string "aa454" ·@freenet.carleton.ca")
http://cbbrowne.com/info/wp.html
"If the  future navigation system [for  interactive networked services
on the NII] looks like  something from Microsoft, it will never work."
-- Chairman of Walt Disney Television & Telecommunications
From: Samantha Skyler
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <7271dfd0.0206140904.75ac54b2@posting.google.com>
> % clisp -c filename.lisp
>   will generate filename.fas/filename.lib, and those should load and
>   run more quickly than what you've got running now.
> 
> If that does not suffice, you should look into installing CMUCL, which
> can compile to native code on IA-32.  With it, you would do:
> ] (compile-file "filename.lisp")
> and find that it generates filename.x86f, which contains native code,
> and which is quite likely to be a lot faster than CLISP was.

I appologize for the ignorance, but I am still very much a RedHat/LISP
newbie.

Now that I have the filname.fas/.lib files, what do I do with them?  I
can't seem to get them to run.

Yes, I freely admit that I have no idea what I am doing :-)

Thanks
-Samantha
From: Christopher Browne
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <aed97p$65ic1$1@ID-125932.news.dfncis.de>
The world rejoiced as ··············@hotmail.com (Samantha Skyler) wrote:
>> % clisp -c filename.lisp
>>   will generate filename.fas/filename.lib, and those should load and
>>   run more quickly than what you've got running now.
>> 
>> If that does not suffice, you should look into installing CMUCL, which
>> can compile to native code on IA-32.  With it, you would do:
>> ] (compile-file "filename.lisp")
>> and find that it generates filename.x86f, which contains native code,
>> and which is quite likely to be a lot faster than CLISP was.
>
> I appologize for the ignorance, but I am still very much a RedHat/LISP
> newbie.
>
> Now that I have the filname.fas/.lib files, what do I do with them?  I
> can't seem to get them to run.

You then can load/run it via:
% clisp filename        (note: leave off the ".lisp")
which will run it.

Alternatively:
% clisp
[1]> (load "filename")   ;;; not (load "filename.lisp")
[does whatever the program does, loading the .fas/.lib files...]

What I do to run such things directly from the command line is thus:

-----------  Script that goes in ~/bin --------------
#!/bin/sh
# $Id: fetchnews,v 1.13 2002/06/14 17:19:27 cbbrowne Exp cbbrowne $
cd ~/Lisp
clisp getnews
-----------------------------------------------------

Unfortunately, there's not a particularly good way to chmod a
fas/.lib file to allow it to "execute itself."

The above "thin veil" of a shell script seems not too bad. 
-- 
(concatenate 'string "cbbrowne" ·@acm.org")
http://www3.sympatico.ca/cbbrowne/nonrdbms.html
"Put simply, the antitrust laws in this country are basically a joke,
protecting us just enough to not have to re-name our park service the
Phillip Morris National Park Service." 
-- Courtney Love, Salon.com, June 14, 2000
From: Samantha Skyler
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <3fd88790.0206141652.60d02e1b@posting.google.com>
> You then can load/run it via:
> % clisp filename        (note: leave off the ".lisp")
> which will run it.


Thanks a bunch!  You just increased my speed by a factor of 5.

A very greatful,
-Samantha
From: Christopher Browne
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <aeed17$6fhre$1@ID-125932.news.dfncis.de>
A long time ago, in a galaxy far, far away, ··············@hotmail.com (Samantha Skyler) wrote:
>> You then can load/run it via:
>> % clisp filename        (note: leave off the ".lisp")
>> which will run it.

> Thanks a bunch!  You just increased my speed by a factor of 5.

Happy to see another satisfied customer :-).

It's a little surprising that there is such a performance difference;
I keep observing it, but am not sure just why the compile to bytecode
changes performance so much.
-- 
(concatenate 'string "cbbrowne" ·@acm.org")
http://cbbrowne.com/info/multiplexor.html
"I've seen  a look in dogs'  eyes, a quickly vanishing  look of amazed
contempt,  and I  am convinced  that basically  dogs think  humans are
nuts."  -- John Steinbeck
From: Paul F. Dietz
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <3D0B1546.B8682641@dls.net>
Christopher Browne wrote:

> It's a little surprising that there is such a performance difference;
> I keep observing it, but am not sure just why the compile to bytecode
> changes performance so much.

Macro expansion overhead?

	Paul
From: Christopher Browne
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <aefe4c$60852$1@ID-125932.news.dfncis.de>
Centuries ago, Nostradamus foresaw when "Paul F. Dietz" <·····@dls.net> would write:
> Christopher Browne wrote:
>
>> It's a little surprising that there is such a performance difference;
>> I keep observing it, but am not sure just why the compile to bytecode
>> changes performance so much.
>
> Macro expansion overhead?

That oughtn't to affect each iteration through a loop.

There must be _some_ sort of optimization that the bytecompiler goes
through that doesn't happen when it loads code via the reader.

Consider the following:

(defvar foo 0)
(loop
    for ii from 1 to (* 656 656)
    do (incf foo))
(format t "Done- ~D Iterations ~%" foo)

Saved as "shortsamp.lisp"

% time clisp shortsamp
Done- 430336 Iterations 
clisp shortsamp  8.04s user 0.21s system 79% cpu 10.385 total
% clisp -c shortsamp
[messages omitted]
% time clisp shortsamp   
Done- 430336 Iterations 
clisp shortsamp  0.19s user 0.00s system 87% cpu 0.217 total
%

From 8.04 seconds to 0.19 seconds.

Then change it to use a defun:
======================================================================
(defun sample ()
  (let ((foo 0))
    (loop
	for ii from 1 to (* 656 656)
	do (incf foo))
    (format t "Done- ~D Iterations ~%" foo)))

(sample)
======================================================================
% time clisp shortsamp
Done- 430336 Iterations 
clisp shortsamp  1.92s user 0.01s system 78% cpu 2.456 total
% clisp -c shortsamp; time clisp shortsamp   
Done- 430336 Iterations 
clisp shortsamp  0.14s user 0.01s system 89% cpu 0.167 total
%

The difference isn't as dramatic here.  I'm not sure what the factor
of 10-100 difference is coming from, regardless.
-- 
(concatenate 'string "chris" ·@cbbrowne.com")
http://www3.sympatico.ca/cbbrowne/commonlisp.html
"In  America,  we  have   a  two-party system.   There   is the stupid
party. And there is the evil party.  I am proud to  be a member of the
stupid party.   Periodically,  the two  parties  get  together  and do
something   that   is  both stupid and    evil.    This  is called  --
bipartisanship."  -- Republican congressional staffer
From: Dave Pearson
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <slrnags4hh.erg.davep.news@hagbard.davep.org>
* Christopher Browne <········@acm.org>:

> Unfortunately, there's not a particularly good way to chmod a fas/.lib
> file to allow it to "execute itself."

clisp's impnotes.html documents a number of ways of doing this in various
environments.

-- 
Dave Pearson:                   |     lbdb.el - LBDB interface.
http://www.davep.org/           |  sawfish.el - Sawfish mode.
Emacs:                          |  uptimes.el - Record emacs uptimes.
http://www.davep.org/emacs/     | quickurl.el - Recall lists of URLs.
From: Edi Weitz
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <87vg8lkc5j.fsf@agharta.de>
··············@hotmail.com (Samantha Skyler) writes:

> I appologize for the ignorance, but I am still very much a
> RedHat/LISP newbie.
> 
> Now that I have the filname.fas/.lib files, what do I do with them?
> I can't seem to get them to run.
> 
> Yes, I freely admit that I have no idea what I am doing :-)

The usual way to "execute your programs" is to LOAD them from within a
running Lisp image, i.e. it is a bit different from what you might be
used to from other languages like C or Perl.

However, you can achieve similar behaviour with Lisp, too.

Here are some ways to do it with CLISP:

  <http://clisp.sourceforge.net/impnotes.html#quickstart>

Here's a Linux-specific way to do it with CMUCL:

  <http://users.actrix.co.nz/mycroft/runlisp.html>

The following page explains another way (not Linux-specific) for
CMUCL:

  <http://ww.telent.net/cliki/CMUCL%20Hints>
  (see the section entitled "CMUCL shell scripts")

You should also note that the commercial Common Lisp implementations
from vendors like Franz or Xanalys are able to create stand-alone
executables.

Hope that helps,
Edi.
From: Paul Wallich
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <pw-49072E.15444814062002@reader1.panix.com>
In article <··············@agharta.de>, Edi Weitz <···@agharta.de> 
wrote:

>··············@hotmail.com (Samantha Skyler) writes:
>
>> I appologize for the ignorance, but I am still very much a
>> RedHat/LISP newbie.
>> 
>> Now that I have the filname.fas/.lib files, what do I do with them?
>> I can't seem to get them to run.
>> 
>> Yes, I freely admit that I have no idea what I am doing :-)
>
>The usual way to "execute your programs" is to LOAD them from within a
>running Lisp image, i.e. it is a bit different from what you might be
>used to from other languages like C or Perl.

One important point is that LOAD generally does exactly that. So if your
compiled file consisted of a bunch of defuns, defvars and so forth, those
things will now be defined/bound/whatever. You still have to invoke the
function of your choice before anything happens.

If your fasl file contains an invocation of your top-level function, 
then it will start up when loaded, but most compiled bits won't,
for obvious reasons.

paul
From: Joel Ray Holveck
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <y7celf9u1to.fsf@sindri.juniper.net>
> 1) Is there anyway I can compile my source code into something like an
> executable file for Linux?

Lisp has a different compile model than C / Fortran / etc.  You can
compile individual functions, compile entire files, and so on-- from
within Lisp.

However, this does not normally produce an executable.  Instead, it
produces a compiled file (similar to .o files in some limited
respects), which you can load into a running Lisp.

> 2) If I complied it, would it be any faster?

Generally.

> 3) If so, what do I need to do to compile my source?

I'm not familiar with the CLISP specifics, but the general method to
load a file "foo.lisp" and compile it too:

> (compile-file "foo")
;; Compiling output usually goes here
> (load "foo")

Depending on your implementation, you might need to supply some
extensions.  This will usually be something like:

> (compile-file "foo.lisp")
;; Compiling output usually goes here
> (load "foo.fas")

Hope this helps,
joelh
From: Paolo Amoroso
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <wzELPWBRfm8SRrWMEoIEygAjkm=F@4ax.com>
On 13 Jun 2002 21:52:15 -0700, ··············@hotmail.com (Samantha Skyler)
wrote:

> I need for this program to run as quickly as possible.
> 
> Right now, to run my program, I open up a terminal window (I'm using
> Red Hat 7.3) and type
> 
> CLISP filename.lisp
[...]
> 1) Is there anyway I can compile my source code into something like an
> executable file for Linux?

Sure, you can compile it.


> 2) If I complied it, would it be any faster?

Yes.


> 3) If so, what do I need to do to compile my source?

Evaluate these forms at the CLISP prompt:

  (compile-file "filename.lisp")
  (load "filename")
  (run-your-application)


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README
From: Sam Steingold
Subject: Re: Compile Question? (I'm not sure)
Date: 
Message-ID: <sa0znxtlcsm.fsf@glip.premonitia.com>
> * In message <····························@posting.google.com>
> * On the subject of "Compile Question? (I'm not sure)"
> * Sent on 13 Jun 2002 21:52:15 -0700
> * Honorable ··············@hotmail.com (Samantha Skyler) writes:
>
> 1) Is there anyway I can compile my source code into something like an
> executable file for Linux?

<http://clisp.cons.org/impnotes/quickstart.html>

> 2) If I complied it, would it be any faster?

yes, about 5 times faster.

> 3) If so, what do I need to do to compile my source?

type
        clisp -c file.lisp


-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
He who laughs last did not get the joke.