chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] About peformance of user defined procedures


From: Jörg F . Wittenberger
Subject: Re: [Chicken-users] About peformance of user defined procedures
Date: 01 Aug 2011 19:36:06 +0200

just a wild guess:

On Jul 31 2011, Pedro Henrique Antunes de Oliveira wrote:

Hey.

I have a file map.scm, which contais this code:

(define (mymap1 op ls)
 (let loop ((ls ls) (acc '()))
   (if (null? ls)
       (reverse acc)
       (loop (cdr ls) (cons (op (car ls)) acc)))))
                             ^^^^
This compiles (*probably* and depending on optimisation switches you pass
to the compiler) one call equivalend to (procedure? op).

Since everything around is zero-effort, you basically check loop and
call performance here.

You might also find it funny to try:

(define (mymap1b op ls)
 (let loop ((op op) (ls ls) (acc '()))
   (if (null? ls)
       (reverse acc)
       (loop op (cdr ls) (cons (op (car ls)) acc)))))

which would avoid one indirection per call at the expense of
yet another loop parameter.  Please let me know how much of a difference
that would be.


(define (mymap2 op ls)
 (let loop ((ls ls))
   (if (null? ls)
       '()
       (cons (op (car ls)) (loop (cdr ls))))))

(define (mymap3 op ls)
 (if (null? ls)
     '()
     (cons (op (car ls)) (mymap3 op (cdr ls)))))

(define ls (let loop ((i 0)) (if (= i 1000000) '() (cons i (loop (add1 i))))))

And another four files, f1.scm, f2.scm, f3.scm, f4.scm.

f1.scm
(include "map.scm")
(map add1 ls)

f2.scm
(include "map.scm")
(mymap1 add1 ls)

f3.scm
(include "map.scm")
(mymap2 add1 ls)

f4.scm
(include "map.scm")
(mymap3 add1 ls)

Compiling all four f[1-4].scm files, with csc -O3, I got those results:

f1 took 0.95secs (average)
f2 took 1.65secs (average)
f3 took 1.35secs (average)
f4 took 1.35secs (average)

I understand why f4 and f3 are pretty much the same thing, but what
differs from mine to the built in map that makes the built in so
faster (2-3x faster)?

Interpreted languages have this characteristic that built in
procedures tend to be much faster, but this all is compiled. I suppose
it is possible to make procedures, in chicken/scheme that are as fast
as the built in one. Right?

Note: compiling with -O5 instead of -O3 made the programs 0.1secs "shorter". Note2: this is not about map specifically (I've been looking at some procedures that I have that look somewhat to some built in ones, but are much slower)

_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-u




reply via email to

[Prev in Thread] Current Thread [Next in Thread]