[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help to get this running faster
From: |
David Pirotte |
Subject: |
Re: help to get this running faster |
Date: |
Tue, 05 Sep 2000 12:27:43 +0200 |
Mikael Djurfeldt wrote:
> ...
> 1. The support for optional arguments is currently slow. Don't use
> this in inner loops.
>
> 2. Guile's implementation of continuations is heavy. Again, avoid
> this in inner loops.
>
> 3. `read-line' is currently an interpreted Scheme closure. We should
> optimize this, but haven't got to it yet. If you can use the
> low-level %read-line as a temporary kludge, this will speed up your
> code.
Many thanaks to all suggestions, here is what I did:
can someone give me a little example on how I could get precise figures on
execution time, cons ...
thanks,
david
;; -- module (alto tabreader)
(define-module (alto tabreader))
(export char-pos
get-tokens
load-records)
;; (use-modules (ice-9 optargs))
;; (use-modules (ice-9 format))
(define (char-pos char str start end)
;; (format #t "Char: ~A~%Str: ~A~%Start: ~A~%End: ~A~%"
;; char str start end)
(catch 'exit
(lambda ()
(do ((i start (+ i 1)))
((>= i end) #f)
(if (char=? (string-ref str i) char)
(throw 'exit i))))
(lambda (key index)
index)))
;; (char-pos #\tab "david pirotte")
(define (get-tokens str sep)
(let ((tokens '())
(start 0)
(str-len (string-length str)))
(do ((end (char-pos sep str start str-len)))
((not end)
(reverse! (cons (substring str start str-len) tokens)))
(set! tokens (cons (substring str start end) tokens))
(set! start (+ 1 end))
(set! end (char-pos sep str start str-len)))))
;; (get-tokens "david pirotte musician")
(define (load-records fname field-sep)
(call-with-input-file fname
(lambda (i-stream)
(do ((records '())
(line (%read-line i-stream) (%read-line i-stream)))
((eof-object? (car line)) (reverse! records))
(set! records (cons (get-tokens (car line) field-sep)
records))))))
;; (load-records "/usr/alto/projects/postgres/essai-122.tab" #\tab)
;; (load-records "/usr/alto/projects/psion/revo/backup/palm-adresses.txt" #\tab)