Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23979
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Program logic weirdness? |
| Date | 2014-04-27 14:55 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ljj5pr$qlv$1@dont-email.me> (permalink) |
| References | (2 earlier) <0.a3b4f471693338248a20.20140426123508BST.87y4ys5no3.fsf@bsb.me.uk> <f4a2b34c-d7b7-4974-a6f6-1582ce0045ff@googlegroups.com> <0.6fc64329016b6998cc1a.20140426223412BST.87a9b76ai3.fsf@bsb.me.uk> <2f7c3181-f823-4cbf-9f86-c3d43e96f5cf@googlegroups.com> <270420141320426439%timstreater@greenbee.net> |
On Sun, 27 Apr 2014 13:20:42 +0100, Tim Streater wrote:
> In article <2f7c3181-f823-4cbf-9f86-c3d43e96f5cf@googlegroups.com>,
> <jonas.thornvall@gmail.com> wrote:
> I see two possibilities:
>
> 1) cond does not depend on the loop counter, i.
>
> 2) cond *does* depend on the loop counter, i.
>
> In case (1) you simply optimise it by taking the if out of the loop
> In case (2) you *cannot* do that and you *must* leave the if [in the
loop].
> This is true whether or not cond is simple or complicated.
There may be a third possibility:
Split the condition.
if ( non loop dependant part of condition )
for ( each thing in loop )
if ( loop dependant part of condition )
{ /* do whatever needs to be done */ }
Or pre-calculate as much as the condition as possible outside the loop,
so that the part of the condition being calculated inside the loop is
less.
But, as I think someone else already said, beware of premature
optimisation. Although I suspect that the dynamic optimisation of loops
in script processors is probably a lot less than that provided in modern
compilers.
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 22:53 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 22:57 -0700
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-26 12:35 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 07:59 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:11 -0700
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-26 22:34 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 00:44 -0700
Re: Program logic weirdness? Tim Streater <timstreater@greenbee.net> - 2014-04-27 13:20 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 06:09 -0700
Re: Program logic weirdness? Tim Streater <timstreater@greenbee.net> - 2014-04-27 18:30 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 12:13 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-28 02:33 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 06:25 -0700
Re: Program logic weirdness? Denis McMahon <denismfmcmahon@gmail.com> - 2014-04-27 14:55 +0000
Re: Program logic weirdness? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-27 15:41 +0100
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-27 13:57 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 23:18 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-25 23:23 -0700
Re: Program logic weirdness? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-04-26 15:06 +0200
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:00 -0700
Re: Program logic weirdness? jonas.thornvall@gmail.com - 2014-04-26 08:06 -0700
csiph-web