Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21351

Re: Strawmans prime sieve/filter

Message-ID <2003588.RNWghBxnIG@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-09-15 03:32 +0200
Subject Re: Strawmans prime sieve/filter
Newsgroups comp.lang.javascript
References (11 earlier) <0.7296b1b07acee9593ab0.20130914061641BST.87fvt8kmo6.fsf@bsb.me.uk> <1481633.v4UOFUmKin@PointedEars.de> <0.69f8137d78f7345f3b42.20130914124902BST.87a9jflj2p.fsf@bsb.me.uk> <3366592.al44JOn7Vm@PointedEars.de> <0.e7c48dbac05ddcc7de7b.20130914215109BST.878uyzjfeq.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Ben Bacarisse wrote:
>>> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>>>> Ben Bacarisse wrote:
>>>>> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>>>>>> Ben Bacarisse wrote:
>>> <snip>
>>>>>>> but that all the deleting decreases the runtime-efficiency.  In what
>>>>>>> sense has it been optimised?
>>>>>>
>>>>>> - it can store primes up to 2⁵³−1 (an Array instance can only hold
>>>>>>   2³²−1 elements)
>>>>>> - reduced memory usage (Object instead of Array)
>>>>>> - potentially faster (no extra Array.prototype.push() calls)
>>>>>> - post-increment replaced with pre-increment (maybe faster)
>>>>> 
>>>>> But it could also be slower and use exactly the same amount of memory.
>>>>> In fact that is the case in both engines I tested.  As posted, your
>>>>> "optimised" version did not finish in two minutes when run under
>>>>> nodejs,
>>>>> and was about 4 to 5 times slower than mine in rhino.  That does not
>>>>> match what I think of as optimised code.
>>>>
>>>> If you think of optimization only in terms of runtime-efficiency, you
>>>> are correct.
>>> 
>>> I think of it in engineering terms, not theoretical ones.  You cite
>>> three advantages: increased range, memory use, and speed.  Do you know
>>> of any engine in which any of the three advantages is realised?
>>
>> (I had listed *four*.)
> 
> You list four changes, but they confer three potential advantages.

Wrong.

>>  Free memory permitting (see below), the first
>> advantage certainly appears to be realized in Google V8 in Chromium
>> “Version 29.0.1547.57 Debian jessie/sid (217859)”:
> 
> I don't want to install that version but in version 28.0.1500.71 your
> code stands no chance of going beyond 2^32.

Neither has the “push to Array” approach because, unfortunately, ECMAScript 
arrays can have at most 2³²−1 elements.  So any prime candidates you could 
confirm with that approach (free memory permitting) are not visible to the 
caller.  *That* is the main benefit of the “set Object property” approach.

And why should I optimize code for *obsolete* browser versions?  It is not 
like anyone would be keeping v28, or v29, for that matter, for very long.  
With rapid releases, in Chromium we are beyond those times when you had to 
consider a number of past major versions.

> I can't get it

What, exactly?  As you have identified the “delete” operation as a potential 
disadvantage, have you removed that operation and re-checked?

> to go to 2 million, let alone the 20 million that was the posted example. 
> 2^53-1 is fantasy.

Why?
 
> I think I see the problem.  You take each of your four modifications and
> consider what they might do in the right circumstances.  And, yes, each
> one might help in this or other programs.  I was just complaining 

Usenet is not a right.

> that you characterised the code as "optimised".  If an EcmaScript expert
> like you optimises my code, I'd expect *the posted code* to realise *some*
> of the supposed benefits in a major implementation like V8. 

It *is* optimized.  Again, optimization means something else than you think 
it does.  In which way does the code not realize *some* of the mentioned 
benefits?

> Instead it just exercises the fan of my laptop.

Maybe you are using it wrong.  With that many operations, you most certainly 
want to run it with window.setTimeout() in order to prevent UI lockup.  And 
certainly your fan would go up; it is quite a number crunching your CPU has 
to do then.  Maybe, as Stefan indicated, ECMAScript implementations are just 
the wrong languages for number crunching.  That does not mean the approach 
is wrong.
 
> <patronising stuff snipped>

Your customer attitude makes me sick.  Go away.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-08 19:09 -0700
  Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 05:57 +0200
    Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-08 21:22 -0700
    Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-08 21:50 -0700
      Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 13:45 +0200
        Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-09 06:33 -0700
        Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-09 06:41 -0700
          Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 18:37 +0200
          Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 19:54 +0200
            Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-09 12:46 -0700
              Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 23:25 +0200
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-09 14:58 -0700
        Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-11 10:39 +0200
          Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-11 02:54 -0700
          Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-11 12:59 +0200
          Re: Strawmans prime sieve/filter Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-09-12 20:17 +0100
            Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-13 02:27 +0200
              Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-13 04:03 +0200
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-12 19:30 -0700
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-13 05:15 +0200
                Re: Strawmans prime sieve/filter Stefan Weiss <krewecherl@gmail.com> - 2013-09-13 05:27 +0200
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-13 08:26 -0700
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-13 08:15 -0700
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-13 19:13 +0200
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-13 17:15 -0700
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-14 01:55 +0100
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-14 04:20 +0200
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-14 06:16 +0100
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-14 12:10 +0200
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-14 12:49 +0100
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-14 15:23 +0200
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-14 21:51 +0100
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-15 03:32 +0200
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-15 04:07 +0100
                Re: Strawmans prime sieve/filter Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-15 18:57 +0200
                Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-15 19:24 +0100
                Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-14 20:37 -0700
                Re: Strawmans prime sieve/filter Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-09-14 19:38 +0100
    Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-08 22:26 -0700
      Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-10 22:48 +0100
        Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-11 00:36 -0700
          Re: Strawmans prime sieve/filter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-11 14:47 +0100
    Re: Strawmans prime sieve/filter jonas.thornvall@gmail.com - 2013-09-08 22:33 -0700
      Re: Strawmans prime sieve/filter "Chris M. Thomasson" <no@spam.invalid> - 2013-09-09 21:08 -0700
        Re: Strawmans prime sieve/filter "Chris M. Thomasson" <no@spam.invalid> - 2013-09-10 08:52 -0700
  Re: Strawmans prime sieve/filter Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-09-10 19:08 +0100
  Re: Strawmans prime sieve/filter "Chris M. Thomasson" <no@spam.invalid> - 2014-04-10 22:02 -0700
    Re: Strawmans prime sieve/filter "Chris M. Thomasson" <no@spam.invalid> - 2014-05-02 15:39 -0700
      Re: Strawmans prime sieve/filter "Chris M. Thomasson" <no@spam.invalid> - 2014-05-02 15:54 -0700

csiph-web