zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Ray Andrews <rayandrews@eastlink.ca>, Zsh Users <zsh-users@zsh.org>
Subject: Re: efficiency
Date: Sat, 4 Feb 2017 15:05:13 +0000	[thread overview]
Message-ID: <20170204150513.4087c834@ntlworld.com> (raw)
In-Reply-To: <b6cf1ad2-056f-c093-fef8-74c995ee6dbd@eastlink.ca>

On Fri, 03 Feb 2017 18:55:53 -0800
Ray Andrews <rayandrews@eastlink.ca> wrote:
> echo "\nSTOP TIMER. REAL RUNTIME: $((now-start)) MILISECONDS 
> ($(((now-start)/60000)):${(l:2::0:)$(((now-start)/1000%60))}) $@"
> 
> integer -x base=$(((now-start)/1000))
> echo "\nSTOP TIMER. REAL RUNTIME: $((now-start)) MILISECONDS 
> ($(($base/60)):${(l:2::0:)$(($base%60))}) $@"
> 
> ... is there any real advantage to the second line?  Obviously I'm 
> trying to cut down on duplicate calculation, and in the real world it 
> hardly matters, but as a point of principal, which is better?

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


  reply	other threads:[~2017-02-04 15:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-04  2:55 efficiency Ray Andrews
2017-02-04 15:05 ` Peter Stephenson [this message]
2017-02-04 15:39   ` efficiency Ray Andrews
2017-02-04 15:47     ` efficiency Peter Stephenson
2017-02-04 16:38       ` efficiency Ray Andrews
2017-02-04 16:47         ` efficiency Peter Stephenson
2017-02-04 17:39           ` efficiency Ray Andrews

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170204150513.4087c834@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.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.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).