unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Leo Liu <sdl.web@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: why is reverse a string in-place so much slower than a vector?
Date: Fri, 25 Apr 2014 16:17:42 +0800	[thread overview]
Message-ID: <m338h1n7q1.fsf@gmail.com> (raw)
In-Reply-To: m37g6dn7z3.fsf@gmail.com

On 2014-04-25 16:12 +0800, Leo Liu wrote:
> (defun rev (a)
>   (let ((l (length a)))
>     (dotimes (i (floor l 2) a)
>       (cl-rotatef (aref a i) (aref a (1- (- l i)))))))

Sorry didn't finish the post.

Assume we are in a buffer visiting subr.el:

(benchmark-run 1 (rev (buffer-string)))
(11.774416366 1 0.060193897999999635)

(benchmark-run 1 (rev (cl-coerce (buffer-string) 'vector)))
(0.067042623 0 0.0)

So why is this so much slower on string?

Leo




  reply	other threads:[~2014-04-25  8:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25  8:12 why is reverse a string in-place so much slower than a vector? Leo Liu
2014-04-25  8:17 ` Leo Liu [this message]
2014-04-25  8:55   ` Rüdiger Sonderfeld
2014-04-25  9:14   ` Andreas Schwab
2014-04-25  9:35     ` Leo Liu
2014-04-25 11:00       ` Andreas Schwab
2014-04-26  0:19         ` Leo Liu

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=m338h1n7q1.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=emacs-devel@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).