Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Give alert if form checkbox array is empty Date: Thu, 21 Jan 2016 08:54:06 +0100 Organization: PointedEars Software (PES) Lines: 42 Message-ID: <9693913.xKMCTVlTbh@PointedEars.de> References: <1851504.v7CTRd67sv@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1453362847 30490 eJwFwYkBwCAIBLCVUO/RccTC/iM04dLQM0SBzc4IygfK2bEV98ld28sanF80LAYa57qy5g8A8hBO (21 Jan 2016 07:54:07 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 21 Jan 2016 07:54:07 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVCE+MU+T3H6F3sNCY9EA4CG7ulNCazym2As9KqT5RrrF9plHn7qdBqytNPMTKfPOg/AFYcBXM Cancel-Lock: sha1:7yLrveqDFf3sL358jabxdDPm/5U= X-NNTP-Posting-Host: eJwNysEBwCAIA8CVlJBA15E2+49g732EtqZSVNJ0CH4G8XmCXOlAT/UG/2CdPEcudb1RgVkXCwAQTw== Xref: csiph.com comp.lang.javascript:29390 Stefan Weiss wrote: > On 01/21/2016 00:59, Thomas 'PointedEars' Lahn wrote: >> You should familiarize yourself with the Array methods introduced with >> implementations of ECMAScript Edition 5 at the latest, in order to not >> write explicit loops where they are not necessary. Examples have been >> given. >> >> Keep in mind that the built-in implementation of an algorithm is >> naturally always the most efficient one to use as it is, at best, >> provided in machine code already. > > Had you tested this, you would have discovered that your version - the > one with `[].slice.call(...)` - takes 2 to 17 times longer than the > simple loop, depending on the browser and which checkboxes are checked. Irrelevant argument as that was _not_ what I as referring to. Besides, you are deliberately ignoring compilation here, but considering it elsewhere. > Also, storing `subjectTypes.length` in a variable has almost no benefit: > it makes the loop a tiny bit faster in Firefox (about 5 nanoseconds per > iteration on my laptop), and a tiny bit slower in Chrome (about the same > difference in the other direction). Making assumptions about the > performance of modern JS engines without testing or intimate knowledge > of the internal optimizations is pointless. It has been shown in this newsgroup to be much more efficient in general. Your test methodology is flawed. > Not that speed matters in this case - there are four checkboxes to test, > what kind of performance do you think we need for that? But you were > criticizing posted code for its performance and at the same time > advocating a slower and less readable version, so I thought you'd like > to know. Your logic is flawed, too. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.