help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing the Emacs engine to Guile


From: Pascal J. Bourguignon
Subject: Re: Changing the Emacs engine to Guile
Date: Wed, 08 Dec 2010 15:15:12 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Cecil Westerhof <Cecil@decebal.nl> writes:

> Op maandag 21 jun 2010 18:36 CEST schreef Andreas Politz:
>
>> very big performance hit. I did absolutely nothing to support this
>> assumption, which shows that Guile is 2½ times slower. So I was
>
> Attached the Guile script.
>
>
> #!/usr/bin/guile \
> -e main -s
> !#
> (use-modules (ice-9 rdelim)
>              (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 (string-replace this-line
>                                        substitute-str
>                                        start-match end-match
>                                        start-match end-match)
>                        output-file))
>     (close-port output-file)
>     (close-port input-file)))
>
>
> My Emacs Lisp script:
>     emacs -batch --eval='
>       (defun substitute-expression(input-file output-file reg-exp 
> substitute-str)
>         (let ((match-length))
>           (switch-to-buffer (find-file-noselect input-file t t))
>           (buffer-disable-undo)
>           (while (re-search-forward reg-exp nil t)
>             (setq match-length (- (point) (match-beginning 0)))
>             (while (> match-length (length substitute-str))
>               (setq substitute-str (concat substitute-str substitute-str)))
>             (replace-match (substring substitute-str 0 match-length))
>           )
>           (write-region (point-min) (point-max) output-file)))
>     ' --eval='
>       (byte-compile '"'"'substitute-expression)
>     ' --eval='
>       (substitute-expression "'"${inputFile}"'"
>                              "'"${outputFile}"'"
>                              "'"${regExp}"'"
>                              "'"${substituteStr}"'")
>     ' 2>/dev/null

AFAIK, these two programs don't do the same thing.  Therefore you
cannot compare their timings in any meaningful way.


What's more, you cannot compare apples and oranges, that is, compare
generic regular expression code in scheme, and compare highly
optimized code to edit a buffer written in C, called from emacs lisp,
to compare the two VM for use in emacs.

When/if emacs is rewritten to use guile, its buffer editing library
written in C will stay the same and be called the same way from scheme
than it is from emacs lisp.  This won't impact their performance.

So you should rather compare code that doesn't use any library, if you
want to compare the emacs VM vs. the guile VM.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]