Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39897
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Loop optimisation. |
| Date | 2021-04-11 11:36 +0100 |
| Organization | A little, after lunch |
| Message-ID | <s4ujfh$h3l$3@dont-email.me> (permalink) |
| References | <s4snvd$cr0$1@dont-email.me> <86e3bc08-8877-45ce-9881-519d0a41b9c0n@googlegroups.com> |
On 11/04/2021 06:22, Michael Haufe (TNO) wrote: > On Saturday, April 10, 2021 at 12:41:08 PM UTC-5, The Natural Philosopher wrote: >> Does Js do it? >> >> I have some close to real time audio processing code and I want it to >> run floating point on a raspberry Pi - no FP coprocessors so no wasted >> cycles required. >> >> The question is - in C if you do something like >> >> function (int x) >> for(somecondition) >> if (x greater than whatever) >> extra blah; >> else completely different blah; >> endfor >> >> will one hopes result in two completely different loops being >> established so that conditionl is actually evaluated outside the loop - >> i.e >> >> function (int x) >> if (x greater than whatever) >> for(somecondition) >> extra blah; >> endfor >> else >> for(somecondition) >> completely different blah; >> endfor >> endif >> >> is what a decent compiler optimised for speed might well do. >> >> Does javascript though? > > Modern JavaScript engines use JIT compilation. Depending on what you are doing it can be faster than the equivalent C code. A couple examples: > > <https://www.reddit.com/r/javascript/comments/bnnrnt/javascript_faster_than_c_to_execute_mathematical/> > <https://gist.github.com/spion/3049314> > > If you want more details on why that's the case here is one description among many: > > <https://hacks.mozilla.org/2017/02/a-crash-course-in-just-in-time-jit-compilers/> > > So you may think you're using floats, but in reality it may have converted those to int32 or smaller as well as inlined and compiled to machine code a significant portion of your script. > >> And of course Javascript makes all numbers floating point...so the >> comparison will be cycle hungry comparing two floats > > No, it doesn't. JavaScript has more than just floats and the JIT will find opportunities to utilize smaller number types behind the scenes where possible and appropriate. > That is useful information, thanks. It seems that 'test and try' is the optimal approach. So far its no issues at all on Intel hardware as far as I have developed it, or android on an ARM ... -- Microsoft : the best reason to go to Linux that ever existed.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-10 18:41 +0100
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-10 19:14 +0100
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:33 +0100
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-11 15:03 +0100
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-11 07:38 -0700
Re: Loop optimisation. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-04-11 13:36 -0700
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-12 18:05 +0100
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 23:16 +0100
Re: Loop optimisation. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-04-13 05:19 -0700
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-13 06:21 -0700
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 01:36 +0100
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-12 18:04 +0100
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 23:09 +0100
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-13 20:08 +0100
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-13 21:41 +0100
Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-14 18:24 +0100
Re: Loop optimisation. Kristjan Robam <he12457@hotmail.com> - 2021-04-10 13:36 -0700
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:34 +0100
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-10 22:22 -0700
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:36 +0100
Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 02:20 +0200
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-14 06:48 -0700
Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 17:31 +0200
Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 18:00 +0200
Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-14 19:25 +0100
Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 23:10 +0200
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 09:45 -0700
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 09:43 -0700
Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-17 21:45 +0200
Re: Loop optimisation. Scott Sauyet <scott.sauyet@gmail.com> - 2021-04-18 19:06 -0700
Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 08:50 -0700
csiph-web