From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 656 invoked by alias); 4 Feb 2017 16:09:36 -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: 22436 Received: (qmail 18738 invoked from network); 4 Feb 2017 16:09:36 -0000 X-Qmail-Scanner-Diagnostics: from mta04.eastlink.ca by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(24.224.136.10):SA:0(-0.7/5.0):. Processed in 1.878181 secs); 04 Feb 2017 16:09:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.eastlink.ca designates 24.224.136.10 as permitted sender) X-Authority-Analysis: v=2.2 cv=ZvqvEJzG c=1 sm=1 tr=0 a=aWG3ZaPfpGbmBTXoUM+q2Q==:117 a=aWG3ZaPfpGbmBTXoUM+q2Q==:17 a=N659UExz7-8A:10 a=jp7F-6PWGEd_xi6oG5gA:9 a=_fLxHGGXf2wfSfxN:21 a=ceQ764Ih2RPQMoDu:21 a=pILNOxqGKmIA:10 X-EL-IP-NOAUTH: 24.207.17.185 Subject: Re: efficiency To: Peter Stephenson , Zsh Users References: <20170204150513.4087c834@ntlworld.com> From: Ray Andrews Message-id: Date: Sat, 04 Feb 2017 07:39:28 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-version: 1.0 In-reply-to: <20170204150513.4087c834@ntlworld.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 04/02/17 07:05 AM, Peter Stephenson wrote: > On Fri, 03 Feb 2017 18:55:53 -0800 > Ray Andrews wrote: > > The point of principle here is "don't repeat yourself"; it's better to > do every calculation just once. Probably the main reason for this is > what happens if you decide you need to change the calculation. (For > example, you might decide to round the calculation differently. I'm clearly > not suggesting you need to!) Then you only need to change one place. > Getting used to that does help you avoid pitfalls in less trivial cases... > > pws > Thanks Peter. Yes I understand that as a point of general programming, I think what I was really asking is if, in an interpreted language the time spent calculating is offset by the time spent parsing. That is, in C you'd be more efficient doing the calculation once (besides what you say above), but maybe in zsh the important thing is to reduce the number of lines or the number of variables or something like that. Or, on the contrary, maybe the simpler form is doubly better since the lines are shorter and thus save parsing time as well as calculation time. Actually, I just realized that the thing can time itself: $ . ./timer; timer start; timer start; timer; timer stop; timer stop , so I tried both ways and: echo "\nSTOP TIMER. REAL RUNTIME: $((now-start)) MILISECONDS ($(((now-start)/60000)):${(l:2::0:)$(((now-start)/1000%60))}) $@" ... turns out to be faster by a whopping milisecond or two, which surprises me. But as you say, the other way is better code of course. This isn't important, I'm just curious.