[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Difference when calling guile script from C vs interpreter
From: |
Jean Rene Dawin |
Subject: |
Difference when calling guile script from C vs interpreter |
Date: |
Tue, 20 Oct 2020 14:58:40 +0200 |
User-agent: |
Mutt/1.9.4 (2018-02-28) |
Hi,
when following guile script:
______ gp.guile _________
(use-modules (statprof))
(use-modules (system vm program))
;Scalar product
(define (sp a b)
(+
(* (car a)(car b))
(* (cdr a)(cdr b))
)
)
(define size 444100)
(define (run)
(let ((accu 0.001)
(r (make-f32vector size 0.0))
)
(let lp ((j 0) )
(when (< j size)
(set! accu (+ accu 0.001))
(f32vector-set! r j (sp (cons accu (* 2 accu)) (cons (* 3 accu)
(* 5 accu))))
(lp (+ j 1) )
)
)
(display (f32vector-ref r (- size 1)))(newline)
)
)
(statprof run)
(display (program? run))(newline)
______________________________
is run from the interpreter, the output shows the following:
scheme@(guile-user)> (load "gp.guile")
;;; note: source file /home/gp.guile
;;; newer than compiled
/home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go
;;; compiling /home/gp.guile
;;; compiled /home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go
2563934.0
% cumulative self
time seconds seconds procedure
50.00 0.33 0.16 /home/gp.guile:12:0:run
28.57 0.09 0.09 %after-gc-thunk
21.43 0.14 0.07 /home/gp.guile:5:0:sp
0.00 0.09 0.00 anon #x7fe262d41380
---
Sample count: 14
Total time: 0.327908556 seconds (0.121140347 seconds in GC)
#t
When the same script is loaded from following C program:
_____ gp.c _______
#include <libguile.h>
int main(int argc, char **argv)
{
scm_init_guile();
scm_c_primitive_load("/home/gp.guile");
return 0;
}
___________________
the result looks like this:
$ gcc -o gp gp.c $(guile-config compile) $(guile-config link)
$ ./gp
2563934.0
% cumulative self
time seconds seconds procedure
15.60 0.30 0.30 ice-9/eval.scm:226:7
12.84 0.59 0.25 ice-9/eval.scm:159:9
12.84 0.25 0.25 ice-9/eval.scm:182:7
6.42 3.49 0.12 ice-9/eval.scm:618:6
6.42 0.55 0.12 ice-9/eval.scm:159:9
5.50 0.25 0.11 ice-9/eval.scm:625:6
5.50 0.11 0.11 ice-9/eval.scm:123:11
3.67 0.07 0.07 ice-9/eval.scm:282:4
3.67 0.07 0.07 ice-9/eval.scm:124:11
3.67 0.07 0.07 srfi/srfi-4.scm:85:20:f32vector-set!
2.75 0.53 0.05 ice-9/eval.scm:159:9
2.75 0.20 0.05 ice-9/eval.scm:191:12
2.75 0.12 0.05 ice-9/eval.scm:263:9
2.75 0.07 0.05 ice-9/eval.scm:155:9
1.83 1.10 0.04 ice-9/eval.scm:163:9
1.83 0.46 0.04 ice-9/eval.scm:159:9
1.83 0.04 0.04 ice-9/eval.scm:336:13
1.83 0.04 0.04 ice-9/eval.scm:222:7
1.83 0.04 0.04 ice-9/eval.scm:590:16
1.83 0.04 0.04 ice-9/eval.scm:333:13
0.92 0.02 0.02 ice-9/eval.scm:273:7
0.92 0.02 0.02 ice-9/eval.scm:224:11
0.00 0.05 0.00 ice-9/eval.scm:155:9
---
Sample count: 109
Total time: 1.939099187 seconds (0.570765622 seconds in GC)
#t
Is this difference expected?
It is 6 times slower when called from C versus from the interpreter.
And the statprof output of the C version shows calls in ice-9/eval.scm
but from the interpreter it doesn't. As I'm new to guile, any
hints would be helpful.
This is GNU Guile 2.2.6 on x86_64 GNU/Linux.
Regards,
Jean Rene Dawin
- Difference when calling guile script from C vs interpreter,
Jean Rene Dawin <=