From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.lisp.guile.user Subject: Performance Date: Fri, 18 Jun 2010 22:50:37 +0200 Organization: Decebal Computing Message-ID: <87vd9gawv6.fsf@linux-lqcw.site> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1276894215 5846 80.91.229.12 (18 Jun 2010 20:50:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 Jun 2010 20:50:15 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 18 22:50:13 2010 connect(): No such file or directory Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OPiVu-0003X9-7c for guile-user@m.gmane.org; Fri, 18 Jun 2010 22:50:10 +0200 Original-Received: from localhost ([127.0.0.1]:45988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPiVt-0001YS-Rb for guile-user@m.gmane.org; Fri, 18 Jun 2010 16:50:09 -0400 Original-Received: from [140.186.70.92] (port=42117 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPiVn-0001YK-Hf for guile-user@gnu.org; Fri, 18 Jun 2010 16:50:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OPiVm-000056-9N for guile-user@gnu.org; Fri, 18 Jun 2010 16:50:03 -0400 Original-Received: from smtp-vbr18.xs4all.nl ([194.109.24.38]:4653) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OPiVl-0008VZ-Tn for guile-user@gnu.org; Fri, 18 Jun 2010 16:50:02 -0400 Original-Received: from linux-lqcw.site (84-53-123-169.wxdsl.nl [84.53.123.169]) by smtp-vbr18.xs4all.nl (8.13.8/8.13.8) with ESMTP id o5IKnxN7036058 for ; Fri, 18 Jun 2010 22:50:00 +0200 (CEST) (envelope-from Cecil@decebal.nl) X-Homepage: http://www.decebal.nl/ User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7900 Archived-At: I have the following code: #!/usr/bin/guile \ -e main -s !# (use-modules (ice-9 rdelim)) (use-modules (ice-9 regex)) (define (main args) (let* ((arg-vector (list->vector args)) (input-file-name (vector-ref arg-vector 1)) (output-file-name (vector-ref arg-vector 2)) (reg-exp (make-regexp (vector-ref arg-vector 3))) (substitute-str (vector-ref arg-vector 4)) (end-match 0) (found-match #f) (input-file (open-file input-file-name "r")) (match-length 0) (output-file (open-file output-file-name "w")) (start-match 0) (this-line "")) (while (not (eof-object? (peek-char input-file))) (set! this-line (read-line input-file)) #! (set! found-match (regexp-exec reg-exp this-line)) (while found-match (set! start-match (match:start found-match)) (set! end-match (match:end found-match)) (set! match-length (- end-match start-match)) (while (> match-length (string-length substitute-str)) (set! substitute-str (string-append substitute-str substitute-str))) (set! found-match (regexp-exec reg-exp this-line (+ end-match 1)))) !# (write-line this-line output-file)) (close-port output-file) (close-port input-file))) When running like this it takes less then 20 seconds to process a 5.000.000 line file. When also executing: (set! found-match (regexp-exec reg-exp this-line)) it takes 33 seconds. When also executing: (while found-match (set! start-match (match:start found-match)) (set! end-match (match:end found-match)) and: (set! found-match (regexp-exec reg-exp this-line (+ end-match 1)))) it takes 75 seconds. And when executing all the code, it takes 95 seconds. Why is this so expensive? I was thinking that Guile was very efficient, but when not just copying, it becomes much slower. Am I doing something wrong? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof