From: Tassilo Horn <tassilo@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Vector and List Performance
Date: Mon, 08 Jun 2009 21:57:29 +0200 [thread overview]
Message-ID: <8763f6mrbq.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: c32bcfbc-f5a1-4bc4-a2fd-075d8f6e9558@e20g2000vbc.googlegroups.com
Nordlöw <per.nordlow@gmail.com> writes:
Hi!
> (defun bench (&rest forms)
> "Convenience wrapper for benchmark-run-compiled."
> (/ (nth 0 (benchmark-run 1024 forms)) 1024))
>
> (let ((length 1000000))
> (cons
> (bench (aref (make-vector length 0) (/ length 2)))
> (bench (nth (/ length 2) (make-list length 0)))
> ))
>
> Strangely I can't seem to find any significant different in
> performance when accessing the middle element in a long vector and
> long list. Shouldn't the random access performance be the big
> difference between vectors and lists? What have I missed?
I think that there's some optimization under the hood. Actually, you
always access the same place in the list/vector. With real random
access, you get the expected result:
--8<---------------cut here---------------start------------->8---
(defun bench ()
(let* ((len 1000000)
(vec (make-vector len 0))
(lst (make-list len 0))
(times 50000))
(cons
(/ (car (benchmark-run times (aref vec (random len)))) times)
(/ (car (benchmark-run times (nth (random len) lst))) times))))
(bench)
==> (1.5999999999999999e-09 . 1.2723999999999999e-06)
--8<---------------cut here---------------end--------------->8---
So random access on a vector is about 1000 times faster.
Bye,
Tassilo
next prev parent reply other threads:[~2009-06-08 19:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-08 17:27 Vector and List Performance Nordlöw
2009-06-08 19:57 ` Tassilo Horn [this message]
2009-06-09 9:30 ` Pascal J. Bourguignon
2009-06-09 11:30 ` Nordlöw
2009-06-09 12:51 ` Pascal J. Bourguignon
2009-06-09 18:13 ` Nordlöw
2009-06-10 8:24 ` Pascal J. Bourguignon
[not found] ` <7c63f45we1.fsf@pbourguignon.informatimago.com>
2009-06-10 8:36 ` Pascal J. Bourguignon
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8763f6mrbq.fsf@thinkpad.tsdh.de \
--to=tassilo@member.fsf.org \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.