[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Performance
From: |
Cecil Westerhof |
Subject: |
Performance |
Date: |
Fri, 18 Jun 2010 22:50:37 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
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
- Performance,
Cecil Westerhof <=
- Re: Performance, Andy Wingo, 2010/06/19
- Re: Performance, Cecil Westerhof, 2010/06/19
- Re: Performance, Andy Wingo, 2010/06/19
- Re: Performance, Cecil Westerhof, 2010/06/21
- Re: Performance, Andy Wingo, 2010/06/21
- Re: Performance, Decebal, 2010/06/21
- Binary packages of Guile development snapshots? (was Re: Performance), Štěpán Němec, 2010/06/22
- Re: Binary packages of Guile development snapshots?, Andy Wingo, 2010/06/22