From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Rene Dawin Newsgroups: gmane.lisp.guile.user Subject: Difference when calling guile script from C vs interpreter Date: Tue, 20 Oct 2020 14:58:40 +0200 Message-ID: <20201020125840.GA14718@math.uni-bielefeld.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19349"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.9.4 (2018-02-28) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Oct 20 14:59:49 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUrEx-0004uK-NF for guile-user@m.gmane-mx.org; Tue, 20 Oct 2020 14:59:47 +0200 Original-Received: from localhost ([::1]:33544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUrEw-0007Tf-Iz for guile-user@m.gmane-mx.org; Tue, 20 Oct 2020 08:59:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUrE0-0007RD-JZ for guile-user@gnu.org; Tue, 20 Oct 2020 08:58:48 -0400 Original-Received: from smtp2.math.uni-bielefeld.de ([129.70.45.13]:41618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUrDy-0004nR-8t for guile-user@gnu.org; Tue, 20 Oct 2020 08:58:48 -0400 Original-Received: from math.uni-bielefeld.de (kvm01.math.uni-bielefeld.de [129.70.45.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by smtp2.math.uni-bielefeld.de (Postfix) with ESMTPSA id 46C6760601 for ; Tue, 20 Oct 2020 14:58:42 +0200 (CEST) Content-Disposition: inline Received-SPF: none client-ip=129.70.45.13; envelope-from=jdawin@math.uni-bielefeld.de; helo=smtp2.math.uni-bielefeld.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/20 08:11:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16988 Archived-At: 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 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