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

2011-08-03 Thread Jörg F . Wittenberger

On Aug 1 2011, Kon Lovett wrote:



On Aug 1, 2011, at 1:05 PM, Jörg F. Wittenberger wrote:


On Aug 1 2011, Pedro Henrique Antunes de Oliveira wrote:


Interesting point.

But I tried it out. In average, it took about the same amount of time
(actualy this was about 0.1s slower).


Looking closer (since you made me curious); there is little magic
about the definition of map as far as I can see.
No special code generation, just:


I think it is open coded. See compiler-syntax.scm for built-in 
compiler-macros.


Ah' I see.  A nice chance to learn something about the compiler internals!

AFAIK This would save some allocations when building the result list.
Is this the case/rationale here?  Or did I miss the point?





(define (##sys#map p lst0)
(let loop ((lst lst0))
  (cond ((eq? lst '()) lst)
  ((pair? lst)
   (cons (p (##sys#slot lst 0)) (loop (##sys#slot lst 1))) )
  (else (##sys#error-not-a-proper-list lst0 'map)) ) ))

(define map)

(##sys#slot lst 0) is in effect (car lst) sans any kind of checks
or calls.  Maybe this helps?



Maybe because the amount of time spent on binding arguments to
parameters is larger than the amount of time of that (procedure? op).

I've heard that some compilers can do something like memoization for
stuff like (procedure? op) (it is possible for that to be done in this
case), which would speed that up.

I've tried compiling with csc -O3 -unsafe (to avoid those checks if
something is a procedure or not), and no actual difference too.

On Mon, Aug 1, 2011 at 2:36 PM, Jörg F. Wittenberger
joerg.wittenber...@softeyes.net wrote:

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 100) '() (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
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicke



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chick



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2011-08-01 Thread Jörg F . Wittenberger

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 100) '() (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
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-u



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2011-08-01 Thread Pedro Henrique Antunes de Oliveira
Interesting point.

But I tried it out. In average, it took about the same amount of time
(actualy this was about 0.1s slower).

Maybe because the amount of time spent on binding arguments to
parameters is larger than the amount of time of that (procedure? op).

I've heard that some compilers can do something like memoization for
stuff like (procedure? op) (it is possible for that to be done in this
case), which would speed that up.

I've tried compiling with csc -O3 -unsafe (to avoid those checks if
something is a procedure or not), and no actual difference too.

On Mon, Aug 1, 2011 at 2:36 PM, Jörg F. Wittenberger
joerg.wittenber...@softeyes.net wrote:
 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 100) '() (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
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-u



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2011-08-01 Thread Jörg F . Wittenberger

On Aug 1 2011, Pedro Henrique Antunes de Oliveira wrote:


Interesting point.

But I tried it out. In average, it took about the same amount of time
(actualy this was about 0.1s slower).


Looking closer (since you made me curious); there is little magic
about the definition of map as far as I can see.
No special code generation, just:

(define (##sys#map p lst0)
 (let loop ((lst lst0))
   (cond ((eq? lst '()) lst)
  ((pair? lst)
   (cons (p (##sys#slot lst 0)) (loop (##sys#slot lst 1))) )
  (else (##sys#error-not-a-proper-list lst0 'map)) ) ))

(define map)

(##sys#slot lst 0) is in effect (car lst) sans any kind of checks
or calls.  Maybe this helps?



Maybe because the amount of time spent on binding arguments to
parameters is larger than the amount of time of that (procedure? op).

I've heard that some compilers can do something like memoization for
stuff like (procedure? op) (it is possible for that to be done in this
case), which would speed that up.

I've tried compiling with csc -O3 -unsafe (to avoid those checks if
something is a procedure or not), and no actual difference too.

On Mon, Aug 1, 2011 at 2:36 PM, Jörg F. Wittenberger
joerg.wittenber...@softeyes.net wrote:

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 100) '() (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
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicke



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2011-07-30 Thread Kon Lovett

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 100) '() (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


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

2011-07-30 Thread Pedro Henrique Antunes de Oliveira
I've taken a look at compiler macros. I see how it could help with
performace, but I don't get how it would help in this case.

Could you explain?

On Sat, Jul 30, 2011 at 8:51 PM, Kon Lovett konlov...@gmail.com wrote:

 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 100) '() (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