Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 37DD5429E25 for ; Wed, 30 Nov 2011 03:53:31 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q0uPr0JxJKSH for ; Wed, 30 Nov 2011 03:53:29 -0800 (PST) Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D7E82431FB6 for ; Wed, 30 Nov 2011 03:53:28 -0800 (PST) Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pAUBrOE2024733; Wed, 30 Nov 2011 13:53:25 +0200 From: Tomi Ollila To: Dmitry Kurochkin , notmuch@notmuchmail.org Subject: Re: [PATCH 1/3] test: add functions to count how much times notmuch was called In-Reply-To: <87aa7evdy8.fsf@gmail.com> References: <1322271878-32614-1-git-send-email-dmitry.kurochkin@gmail.com> <1322450895-32523-1-git-send-email-dmitry.kurochkin@gmail.com> <1322450895-32523-2-git-send-email-dmitry.kurochkin@gmail.com> <87hb1ovsz4.fsf@gmail.com> <87aa7evdy8.fsf@gmail.com> User-Agent: Notmuch/0.10+15~gb5803e9 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2011 11:53:31 -0000 On Wed, 30 Nov 2011 01:03:27 +0400, Dmitry Kurochkin wrote: > Hi Tomi. > > On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila wrote: > > Hi Dmitry. [ ... ] > > > > The (posix) shell command language defines 'Arithmetic Expansion' in > > > > http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004 > > > > I.e. using format $(( expression )) makes shell doing the arithetic itself > > instead of forking a process (or two!) to do so. > > > > I though expr was a builtin. Now I agree that it is better to replace > it with $(()), even though I still prefer the expr syntax. Actually, I thought also that expr was a builtin. That makes the resolution 'forks subshell to execute builtin expr' below wrong. If it were a builtin then bash would also fork only once (to get details right). I re-tested with zsh using 'builtin pwd' and '/bin/pwd' instead of 'expr' -- only one fork in each case. So, those who examined my tests with deep interest also note this correction. > > Normally in this case it is not so big deal (and still it isn't, but...) > > In this particular case the shell wrapper counting notmuch launches and > > exec'ing it the wrapper could do this without fork(2)ing a single time > > (i.e. keep the process count unchanged compared to execing notmuch > > directly) > > > > Anyway, many opinions; as far as it works I'm fine with it :) > > > > Now that you feel relaxed, check the results of some further > > experimentation ;) : > > > > excerpt from man strace: > > > > -ff If the -o filename option is in effect, each processes > > trace is written to filename.pid where pid is the > > numeric process id of each process. > > > > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' > > > > will output '10' and create just one 'forked.' file > > > > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)' > > > > output 10 as expected, but there is now *3* forked. files ! > > > > bash does not optmize; it forks subshell to execute $(...) and then > > there just works as usual (forks subshell to execute builtin expr)) > > > > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 5)' > > > > (the added 'exec' takes off one fork -- just 2 forked. files appear). > > > > I did the same tests using dash, ksh & zsh on linux system, and every one > > of these managed to optimize one fork out in the above 3 fork case. > > > > Thanks for details. > > Regards, > Dmitry > > > > > Tomi Tomi