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