From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: efficiency question on text manipulation using string vs buffer Date: Tue, 24 Mar 2009 19:56:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <95d6eb8d-59c8-4d49-8844-5cd85a84a2f7@z16g2000prd.googlegroups.com> References: <01cc8ac5-0b6c-4f7f-8018-73e644b8bf17@p6g2000pre.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1237957497 16645 80.91.229.12 (25 Mar 2009 05:04:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Mar 2009 05:04:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 25 06:06:15 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LmLJe-0005mV-GC for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Mar 2009 06:06:14 +0100 Original-Received: from localhost ([127.0.0.1]:33098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LmLIH-0008QD-Mq for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Mar 2009 01:04:49 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!postnews.google.com!z16g2000prd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 43 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1237949794 29361 127.0.0.1 (25 Mar 2009 02:56:34 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 25 Mar 2009 02:56:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z16g2000prd.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167960 comp.emacs:98063 X-Mailman-Approved-At: Wed, 25 Mar 2009 00:58:28 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:63253 Archived-At: On Mar 24, 7:34 pm, Kevin Rodgers wrote: > Xah Lee wrote: > > emacs lisp question. > > > it's said that for text manipulation, operation on buffer data type is > > more efficient than operation on string data type. > > > today, i tried to test it, but the difference seems negligible ? My > > tentative test seems to indicate, that after performing 120 thousand > > string replacement, the string method is only 1 second slower. > ... > > It appears to me, testing these commands on a text selection with > > about 122k chars that needs to be replaced, the second version is only > > 1 second slower? (both finishes within 2 or 3 seconds, on a 2007 > > midrange PC) > > > Any comments? > > The version that takes 3 seconds is 50% slower than the version that > takes 2 seconds. LOL Kevin. I think with what little skills i have, i can still do arithmetic fine. The point is, the speed difference is few micro seconds for all practical purposes, at least this particular code comparison. (the version with save-restriction and narrow-to-region might even be slower if the function is called multiple times for its overhead.) I like the version that repeated sets var and repeatedly call replace- regexp-in-string. This is conceptually simple and the concept is universal among langs. The version calling save-restriction and narrow- to-region is emacs specific, requires some specific knowledge about emacs/lisp environment to understand. i somewhat fear, if repeated or recursive call to save-restriction or narrow-to-region or similar might break something. (don't fully understand their details... which involves buffers, marks, etc.) Xah =E2=88=91 http://xahlee.org/ =E2=98=84