From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: point-at-final-line Date: Mon, 29 Jan 2018 16:03:10 +0100 Organization: Aioe.org NNTP Server Message-ID: <86d11sbtch.fsf@zoho.com> References: <868tckgl1y.fsf@zoho.com> <87vafom6af.fsf@bsb.me.uk> <86r2qcf1h2.fsf@zoho.com> <86wp01byil.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1517238447 6765 195.159.176.226 (29 Jan 2018 15:07:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Jan 2018 15:07:27 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 29 16:07:23 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egB1W-0000Z6-Ek for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Jan 2018 16:07:06 +0100 Original-Received: from localhost ([::1]:43414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egB3X-00040M-6O for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Jan 2018 10:09:11 -0500 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 62 Original-NNTP-Posting-Host: VFF8n9P1H/v9pfNWKwEKwA.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org Mail-Copies-To: never X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:R4RBWhWZMTBK+044E/3KbWTrwSY= Original-Xref: usenet.stanford.edu gnu.emacs.help:221757 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115874 Archived-At: 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