From: Valery
Subject: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <bdbfa2d4.0307050614.2f3a0ffd@posting.google.com>
Hi all,

I'd like to make a small projection concerning performance of 
the evaluation of dynamically created function in different 
dynamic languages.

implementations of following languages are concidered: 
Lisp family (including Scheme), Dylan, Python, C# with reflections(?),
<your language here>. 

However I'd like to spent my time on mature enough 
languages/implementations :)

Initial form of my report you could find here:
http://khamenya.ru/dyn-lang-bench/

Please send better implemented test of your languages in this 
thread or directly at:

   khamenya AT mail DOT ru

some related discussions are:

http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&threadm=bdbfa2d4.0307041240.35dbb33%40posting.google.com&prev=/groups%3Fgroup%3Dcomp.lang.lisp%26hl%3Den
http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&threadm=bdbfa2d4.0307041223.356758a4%40posting.google.com&prev=/groups%3Fgroup%3Dcomp.lang.scheme%26hl%3Den

Thank you.
Valery

From: Pascal Costanza
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <costanza-CE97F5.17530405072003@news.netcologne.de>
In article <····························@posting.google.com>,
 ········@mail.ru (Valery) wrote:

> Hi all,
> 
> I'd like to make a small projection concerning performance of 
> the evaluation of dynamically created function in different 
> dynamic languages.
[...]

> 
> Initial form of my report you could find here:
> http://khamenya.ru/dyn-lang-bench/
> 
> Please send better implemented test of your languages in this 
> thread
[...]


I don't have your setup (Windows XP, Pentium IV, 2.4 GHz, 1 GB Ram) but 
rather Mac OS X, G3, 600 MHz, 384 MB Ram.

Here are two versions of the test case in Common Lisp, a straightforward 
and an optimized version.

(defun run ()
  (time 
   (eval 
    '(labels ((fib (x)
                (if (< x 2)
                  1 
                  (+ 
                   (fib (- x 2)) 
                   (fib (1- x))))))
       (fib 41)))))


(defun run-o ()
  (time
   (eval
    '(labels ((fib (x)
                (declare (dynamic-extent x)
                         (fixnum x)
                         (ftype (function (fixnum) fixnum) fib))
                (the fixnum
                  (if (< x 2)
                    1 
                    (+ (fib (the fixnum (- x 2)))
                       (fib (the fixnum (1- x))))))))
       (fib 41)))))


I am not an expert in Common Lisp optimization, so I guess this code is 
either funny or not optimal or both. But I have got the following 
results with Macintosh Common Lisp 5.0:

? (progn (run) (run-o))

(eval '(labels ((fib (x) (if (< x 2) 1 (+ (fib (- x 2)) (fib (1- x)))))) 
(fib 41))) took 94,399 milliseconds (94.399 seconds) to run.
Of that, 49 milliseconds (0.049 seconds) were spent in The Cooperative 
Multitasking Experience.
 7,656 bytes of memory allocated.

(eval '(labels ((fib (x)
                  (declare (dynamic-extent x) (fixnum x) (ftype 
(function (fixnum) fixnum) fib))
                  (the fixnum (if (< x 2) 1 (+ (fib (the fixnum (- x 
2))) (fib (the fixnum (1- x))))))))
         (fib 41))) took 63,715 milliseconds (63.715 seconds) to run.
Of that, 39 milliseconds (0.039 seconds) were spent in The Cooperative 
Multitasking Experience.
 7,648 bytes of memory allocated.

267914296


The code should run on other CL implementations as well.


Pascal
From: Iain Little
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <873chkcuqb.fsf@Ice.i-did-not-set--mail-host-address--so-tickle-me>
Pascal Costanza <········@web.de> writes:

> In article <····························@posting.google.com>,
>  ········@mail.ru (Valery) wrote:
>
>> Hi all,
>> 
>> I'd like to make a small projection concerning performance of 
>> the evaluation of dynamically created function in different 
>> dynamic languages.
> [...]
>
>> 
>> Initial form of my report you could find here:
>> http://khamenya.ru/dyn-lang-bench/
>> 
>> Please send better implemented test of your languages in this 
>> thread
> [...]
>
[...]
>
> (defun run ()
>   (time 
>    (eval 
>     '(labels ((fib (x)
>                 (if (< x 2)
>                   1 
>                   (+ 
>                    (fib (- x 2)) 
>                    (fib (1- x))))))
>        (fib 41)))))
>

Just because you are constructing a function at runtime, doesn't mean
that you can't compile it...

(time
 (eval '(funcall (compile (defun fib (x)
			    (declare (optimize (speed 3) (safety 0) (debug 0))
				     (type fixnum x))
			    (if (< x 2)
				1
				(+ (fib (- x 2))
				   (fib (1- x))))))
	         41)))

With CMUCL on an Athlon XP 1700:

Evaluation took:
  11.12 seconds of real time
  11.12 seconds of user run time
  0.0 seconds of system run time
  0 page faults and
  184696 bytes consed.
From: Bruce Hoult
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <bruce-71A0F3.13143306072003@copper.ipg.tsnz.net>
In article <····························@posting.google.com>,
 ········@mail.ru (Valery) wrote:

> I'd like to make a small projection concerning performance of 
> the evaluation of dynamically created function in different 
> dynamic languages.

This is *not* what people in the dynamic languages community normally 
refer to as creating a function at runtime.  See, for example, _On Lisp_ 
(http://www.paulgraham.com/onlisp.html), in which Paul Graham is quite 
explicit that he's talking about closures, NOT "eval".

I offer the following code in Dylan, which *is* an example of what we 
refer to as creating functions at runtime -- in fact it create a total 
of 41 funtions at runtime:

-------------------------------------------------------
module: fib

define open generic fib(n);

define method fib(n :: <integer>)
  let result =
    if (n < 2)
      1
    else
      fib(n - 1) + fib(n - 2)
    end;
  add-method(fib, method(n == n) result end);
  result;
end;

format-out("fib 41 = %d\n", fib(41))
-------------------------------------------------------
·····@k7:~/programs/dylan/fib > time ./fib 
fib 41 = 267914296

real    0m0.020s
user    0m0.020s
sys     0m0.000s
-------------------------------------------------------

This result obtained with Gwydion Dylan 2.3.10 on a 700 MHz Athlon.

-- Bruce
From: Valery
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <bdbfa2d4.0307090225.2eb8bc6f@posting.google.com>
Eli Barzilay <···@barzilay.org> wrote in message news:<··············@mojave.cs.cornell.edu>...
> "Anton van Straaten" <·····@appsolutions.com> writes:
> 
> Or this Swindle version which is identical to the Dylan one:
> 
>   (defmethod (fib n)
>     (let ((r (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))))
>       (add-method fib (method ((n = n)) r))
>       r))

Any idea why the followin error takes place by Allegro CL?
---------------- 
Warning: Malformed specialized parameter subform: (ADD-METHOD FIB
(METHOD ((N = N)) R))
Warning: Malformed specialized parameter subform: ((R (IF (< N 2) 1 (+
(FIB (- N 1)) (FIB (- N 2))))))
Error: Attempt to access the name field of
       (R (IF (< N 2) 1 (+ (FIB (- N 1)) (FIB (- N 2))))) which is not
       a symbol.
----------------

thanks,
Valery
From: Paul F. Dietz
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <N66cneuES-cBbZaiXTWJgQ@dls.net>
Valery wrote:

> Any idea why the followin error takes place by Allegro CL?

Because the input is blatantly incorrect.

	Paul
From: Marco Antoniotti
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <3F0C2A67.7010501@cs.nyu.edu>
Paul F. Dietz wrote:
> Valery wrote:
> 
>> Any idea why the followin error takes place by Allegro CL?
> 
> 
> Because the input is blatantly incorrect.

This is incorrect for Common Lisp.  But the input is in "Swindle".

Cheers

--
Marco Antoniotti
From: Eli Barzilay
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <sku19u7wkq.fsf@mojave.cs.cornell.edu>
"Paul F. Dietz" <·····@dls.net> writes:

> Valery wrote:
> 
> > Any idea why the followin error takes place by Allegro CL?
> 
> Because the input is blatantly incorrect.

I did say that this was a "Swindle version" of the Dylan program.  The
only thing that was blatantly incorrect in this thread corner is
ignoring that and assuming that if it has parens and `defmethod' then
it must be CL, but under these conditions, blatancy is very common.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Pascal Costanza
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <beguq4$1404$1@f1node01.rhrz.uni-bonn.de>
Valery wrote:
> Eli Barzilay <···@barzilay.org> wrote in message news:<··············@mojave.cs.cornell.edu>...
> 
>>"Anton van Straaten" <·····@appsolutions.com> writes:
>>
>>Or this Swindle version which is identical to the Dylan one:
>>
>>  (defmethod (fib n)
>>    (let ((r (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))))
>>      (add-method fib (method ((n = n)) r))
>>      r))
> 
> 
> Any idea why the followin error takes place by Allegro CL?

Swindle is for Scheme, not for Common Lisp


Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: Kalle Olavi Niemitalo
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <8765mblx1g.fsf@Astalo.kon.iki.fi>
········@mail.ru (Valery) writes:

> Eli Barzilay <···@barzilay.org> wrote in message news:<··············@mojave.cs.cornell.edu>...
>> Or this Swindle version which is identical to the Dylan one:
> Any idea why the followin error takes place by Allegro CL?

The code is not Common Lisp; Swindle appears to be an extension
of PLT Scheme.

http://www.barzilay.org/Swindle/
http://www.cs.cornell.edu/eli/Swindle/clos-doc.html#method
From: Bruce Hoult
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <bruce-9CCE7B.00421110072003@copper.ipg.tsnz.net>
In article <····························@posting.google.com>,
 ········@mail.ru (Valery) wrote:

> Eli Barzilay <···@barzilay.org> wrote in message 
> news:<··············@mojave.cs.cornell.edu>...
> > "Anton van Straaten" <·····@appsolutions.com> writes:
> > 
> > Or this Swindle version which is identical to the Dylan one:
> > 
> >   (defmethod (fib n)
> >     (let ((r (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))))
> >       (add-method fib (method ((n = n)) r))
> >       r))
> 
> Any idea why the followin error takes place by Allegro CL?
> ---------------- 
> Warning: Malformed specialized parameter subform: (ADD-METHOD FIB
> (METHOD ((N = N)) R))
> Warning: Malformed specialized parameter subform: ((R (IF (< N 2) 1 (+
> (FIB (- N 1)) (FIB (- N 2))))))
> Error: Attempt to access the name field of
>        (R (IF (< N 2) 1 (+ (FIB (- N 1)) (FIB (- N 2))))) which is not
>        a symbol.
> ----------------

Because Swindle and CL have nothing to do with each other??

-- Bruce
From: Eli Barzilay
Subject: Re: benchmark cut for evaluation of dynamically created function
Date: 
Message-ID: <sky8z76i95.fsf@mojave.cs.cornell.edu>
Bruce Hoult <·····@hoult.org> writes:

> Because Swindle and CL have nothing to do with each other??

They do share high-level concepts of the object system, to the point
that it is easy translating code.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!