unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Performance
@ 2010-06-18 20:50 Cecil Westerhof
  2010-06-19  9:16 ` Performance Andy Wingo
  0 siblings, 1 reply; 11+ messages in thread
From: Cecil Westerhof @ 2010-06-18 20:50 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-06-22 19:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-18 20:50 Performance Cecil Westerhof
2010-06-19  9:16 ` Performance Andy Wingo
2010-06-19 15:05   ` Performance Cecil Westerhof
2010-06-19 15:44     ` Performance Thien-Thi Nguyen
2010-06-21  9:41       ` Performance Cecil Westerhof
2010-06-19 18:16     ` Performance Andy Wingo
2010-06-21  9:48       ` Performance Cecil Westerhof
2010-06-21 19:34         ` Performance Andy Wingo
2010-06-21 20:34           ` Performance Decebal
2010-06-22 11:33           ` Binary packages of Guile development snapshots? (was Re: Performance) Štěpán Němec
2010-06-22 19:04             ` Binary packages of Guile development snapshots? Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).