On Jul 30, 2011, at 4:43 PM, 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))))) > > (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)?
I think map is one of the procedures "open-coded" by the compiler. > > 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? See compiler macros. > > 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 > Chicken-users@nongnu.org > https://lists.nongnu.org/mailman/listinfo/chicken-users _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users