From: Emanuel Berg <moasen@zoho.com>
To: help-gnu-emacs@gnu.org
Subject: Re: point-at-final-line
Date: Tue, 30 Jan 2018 03:18:18 +0100 [thread overview]
Message-ID: <86vafk9jit.fsf@zoho.com> (raw)
In-Reply-To: mailman.8185.1517248285.27995.help-gnu-emacs@gnu.org
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
next prev parent reply other threads:[~2018-01-30 2:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-27 1:14 point-at-final-line Emanuel Berg
2018-01-27 1:36 ` point-at-final-line Ben Bacarisse
2018-01-27 1:52 ` point-at-final-line John Mastro
2018-01-27 2:50 ` point-at-final-line Emanuel Berg
[not found] ` <mailman.8058.1517017989.27995.help-gnu-emacs@gnu.org>
2018-01-27 2:56 ` point-at-final-line Emanuel Berg
2018-01-27 3:02 ` point-at-final-line Emanuel Berg
2018-01-27 6:11 ` point-at-final-line Marcin Borkowski
[not found] ` <mailman.8063.1517033499.27995.help-gnu-emacs@gnu.org>
2018-01-27 7:05 ` point-at-final-line Emanuel Berg
2018-01-28 16:06 ` point-at-final-line Stefan Monnier
[not found] ` <mailman.8116.1517155644.27995.help-gnu-emacs@gnu.org>
2018-01-28 18:59 ` point-at-final-line Emanuel Berg
2018-01-28 20:36 ` point-at-final-line Eli Zaretskii
[not found] ` <mailman.8132.1517171769.27995.help-gnu-emacs@gnu.org>
2018-01-29 15:03 ` point-at-final-line Emanuel Berg
2018-01-29 16:04 ` point-at-final-line Eli Zaretskii
[not found] ` <mailman.8177.1517241890.27995.help-gnu-emacs@gnu.org>
2018-01-29 16:40 ` point-at-final-line Emanuel Berg
2018-01-29 17:51 ` point-at-final-line Eli Zaretskii
[not found] ` <mailman.8185.1517248285.27995.help-gnu-emacs@gnu.org>
2018-01-30 2:18 ` Emanuel Berg [this message]
2018-01-30 3:32 ` point-at-final-line Eli Zaretskii
2018-01-30 3:50 ` point-at-final-line Stefan Monnier
[not found] ` <mailman.8212.1517284260.27995.help-gnu-emacs@gnu.org>
2018-01-30 14:52 ` point-at-final-line Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86vafk9jit.fsf@zoho.com \
--to=moasen@zoho.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).