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

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

Re: point-at-final-line


From: Emanuel Berg
Subject: Re: point-at-final-line
Date: Mon, 29 Jan 2018 16:03:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Eli Zaretskii wrote:

> Yes, counting lines is fast. But not counting
> lines is even faster.
>
> You don't need to compute the number of the
> current line, you just need to establish
> whether the line current ends at EOB. Right?
> And the line's end is given by
> line-end-position, right?

If you mean like this

(defun point-at-final-line-3 ()
  (= (line-end-position) (point-max)) )

I agree it looks the best thus far, however
with 100 000 lines it is still 0.000005 just
like the others. Anyone else feel free to
create an even bigger file

create-bogus-file () {
    local file=$1
    local lines=$2
    rm -r $file
    for l in {0..$lines}; do
        dd if=/dev/urandom count=1 2> /dev/null |
            sha256sum |
            ( read rnd _; echo $rnd >> $file )
    done
}
alias cbf=create-bogus-file

(defmacro measure-time (&rest body)
  "Measure and return the running time of the code block.
Not mine: http://nullprogram.com/blog/2009/05/28/";
  (declare (indent defun))
  (let ((start (make-symbol "start")))
    `(let ((,start (float-time)))
       ,@body
       (- (float-time) ,start))))

(defun point-at-final-line ()
  (= (line-number-at-pos)
     (line-number-at-pos (point-max)) ))
;; (insert (format "\n;; %f" (measure-time #'point-at-final-line)))
;; 0.000005

(defun point-at-final-line-2 ()
  (save-excursion
    (end-of-line) (= 1 (forward-line 1)) ))
;; (insert (format "\n;; %f" (measure-time #'point-at-final-line-2)))
;; 0.000006

(defun point-at-final-line-3 ()
  (= (line-end-position) (point-max)) )
;; (insert (format "\n;; %f" (measure-time #'point-at-final-line-3)))
;; 0.000006

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

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