From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19966 invoked by alias); 23 Mar 2010 08:33:17 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 14961 Received: (qmail 19374 invoked from network); 23 Mar 2010 08:33:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.220.219 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=k6vzrEhX22LAOk3U7odVxh0+USSnZ3isyJ05NjdGX5A=; b=vPbMeep1DjcBp/2ZQxehexyp3mFl3DS7QuOSzxqaTt+8iYVRz2VvfIU8dED55Opp5R WpL8WE/TnMg3i6EktS8A2lOwtOfgis2p7+vZPf+UJHcZokS3dJMnkcoIuZZ4QaHrl9S1 SaH0KfxdvXDEwfBYTRHhq0v9N/wEpMi5DTPjc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=GDLfIRfY6f5la5oD1Xkq06WPIa3sbLiSMX7wlAnIyEQ4XpBDV+lGANnHIe/cDWpOqq XQO1corz+uA6upqfU+Cpq5DZMhMtfLOW1Q7LQRr8Ymgb4+K9qjHqs46T32QdWL+QIC3n faQ3vxflxC7P6pozPX1sbNYGn1F0ybxrLv4tk= Message-ID: <4BA87B40.8070901@gmail.com> Date: Tue, 23 Mar 2010 09:26:40 +0100 From: "Radoulov, Dimitre" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: zsh-users@zsh.org Subject: Re: Fwd: Re: Brace expansion performance References: <4BA7CC66.6050408@gmail.com> <100322211817.ZM11304@torch.brasslantern.com> In-Reply-To: <100322211817.ZM11304@torch.brasslantern.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 23/03/2010 5.18, Bart Schaefer wrote: > On Mar 22, 9:00pm, Radoulov, Dimitre wrote: > } > } It seams that it's that particular combination with the for loop: > } > } % strace -c zsh -fc 'for i in {1..1000}; do :;done' > > [...] > > } On 22/03/2010 18.22, Bart Schaefer wrote: > }> I'm pretty sure zsh is actually allocating an array of 300000 > }> integers during expansion of that expression, and probably copying > }> it a few times. > } > } Yes, thanks! > } Could this explain such a big difference in the timings? > > Turns out that's not quite it. Do you happen to know whether your zsh > is compiled with --enable-zsh-mem ? With --enable-zsh-mem-debug ? > > Zsh-mem was not enabled. Anyway, with enable-zsh-mem (on my notebook, Ubuntu on VirtualBox) I get similar timings. > If you look at "ltrace -c" instead of "strace" for that same 1000 > integers, here's zsh: > > % time seconds usecs/call calls function > ------ ----------- ----------- --------- -------------------- > 35.83 2.273416 403 5630 strlen > 35.59 2.258366 751 3006 sigprocmask > 6.55 0.415719 48 8594 memset > 4.67 0.296125 48 6055 memcpy > 3.78 0.239621 48 4964 strcmp > 3.57 0.226469 48 4630 mbrtowc > 3.48 0.220989 48 4556 strcpy > 1.55 0.098170 48 2004 fflush > 1.52 0.096682 48 2004 __errno_location > 0.93 0.059187 48 1221 strchr > 0.80 0.050600 50 1001 sprintf > 0.76 0.048399 48 1001 ferror > 0.76 0.048374 48 1000 strcat > (snipped) > > And here's bash: > > % time seconds usecs/call calls function > ------ ----------- ----------- --------- -------------------- > 29.58 3.282781 124 26449 malloc > 29.39 3.261934 125 25933 free > 25.14 2.790494 171 16238 strcpy > 5.14 0.570544 48 11695 __ctype_get_mb_cur_max > 4.83 0.536449 48 11012 memcpy > 2.67 0.295913 48 6101 strcmp > 2.20 0.244207 48 5003 strchr > 0.44 0.048769 48 1002 memset > 0.44 0.048475 48 1000 ferror > 0.08 0.008553 8553 1 qsort > 0.03 0.002880 48 59 mbrtowc > 0.01 0.000828 48 17 sigemptyset > 0.01 0.000698 87 8 sigaction > (snipped) > > Note that bash does significantly more calls to malloc/free, but > does much less signal handling -- and doesn't use stdio at all; and > zsh is spending a lot of calls zeroing out memory and doing multibyte > conversion, which bash doesn't do anywhere near as often. I suspect > this is down to whether the shell stores things in native multibyte > internally or not. > > However, for smaller loops I tried, zsh was consistently faster -- > it's not until you approach six digits of loop bound that zsh begins > to fall behind, at least on my hardware. So I think this is a case > of the shells having optimized for different things, and for what I'd > presume are the more common cases, zsh does just fine. > Thank you for the explanation. Regards Dimitre