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: Tue, 30 Jan 2018 03:18:18 +0100 Organization: Aioe.org NNTP Server Message-ID: <86vafk9jit.fsf@zoho.com> References: <868tckgl1y.fsf@zoho.com> <87vafom6af.fsf@bsb.me.uk> <86r2qcf1h2.fsf@zoho.com> <86wp01byil.fsf@zoho.com> <86d11sbtch.fsf@zoho.com> <86372obou1.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1517278719 21595 195.159.176.226 (30 Jan 2018 02:18:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 Jan 2018 02:18:39 +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 Tue Jan 30 03:18:35 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 1egLVJ-0005Dz-CF for geh-help-gnu-emacs@m.gmane.org; Tue, 30 Jan 2018 03:18:33 +0100 Original-Received: from localhost ([::1]:57999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egLXK-0000PV-5K for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Jan 2018 21:20:38 -0500 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 77 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:sypYNmM2NV+L0qY2AhGaPA3sVdQ= Original-Xref: usenet.stanford.edu gnu.emacs.help:221761 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:115878 Archived-At: Eli Zaretskii wrote: > I'm saying that you _can_ measure this: just > run each function many times in a loop, and > then divide the time by the number of > iterations. This is a standard method of > timing short code fragments. I don't know about that method. The reason is it seems to favor your suggestion. And not by a little! Here are the results in seconds for 10 000 runs in a buffer of 55 lines: ;; point-at-final-line-3 0.08 ;; point-at-final-line-2 0.38 ;; point-at-final-line-1 0.55 The entire code yanked: ;; This file: http://user.it.uu.se/~embe8573/emacs-init/measure.el (require 'cl-lib) (defun point-at-final-line-1 () (= (line-number-at-pos) (line-number-at-pos (point-max) ))) (defun point-at-final-line-2 () (save-excursion (end-of-line) (= 1 (forward-line 1)) )) (defun point-at-final-line-3 () (= (line-end-position) (point-max)) ) (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 create-random-list (max len) (let ((l ())) (cl-loop repeat len do (push (random max) l)) l) ) (defun test-final-line-f (fun pos-list) (cl-loop for p in pos-list do (goto-char p) (apply fun nil) )) (defun test-final-line (its) (let*((max (point-max)) (pos-list (create-random-list max its)) (funs (list #'point-at-final-line-1 #'point-at-final-line-2 #'point-at-final-line-3) ) (times ()) ) (cl-loop for f in funs do (push (list f (measure-time (test-final-line-f f pos-list))) times) ) (goto-char (point-max)) (let ((sorted-times (cl-sort times #'< :key #'cadr))) (cl-loop for time in sorted-times do (insert (format "\n;; %s %0.2f" (car time) (cadr time))) )))) ;; (test-final-line 10000) ;; point-at-final-line-3 0.08 ;; point-at-final-line-2 0.38 ;; point-at-final-line-1 0.55 -- underground experts united http://user.it.uu.se/~embe8573