Path: csiph.com!goblin3!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder.erje.net!2.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Sort at least 5 times faster then native and quicksort Date: Sun, 29 Oct 2017 12:10:53 +0000 Organization: A noiseless patient Spider Lines: 31 Message-ID: <87d156upbm.fsf@bsb.me.uk> References: <8c8816a1-0e4f-4bb4-8a52-94f434e4d599@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b252f5705e435813dbfff633d4cae81b"; logging-data="20802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rsr4rS7Ee9hAi2gU5vcdQhJaskAj0Bhg=" Cancel-Lock: sha1:ID1w37Y+jLRC0NxNLk6UZzsSEEo= sha1:Xe+wwnzqyMbC38wONP9yTSqbEpM= Xref: csiph.com comp.lang.javascript:34230 jonas.thornvall@gmail.com writes: > My sort Algorithm is at least 5 time faster then native and quicks > sort for densely populated samples "where numbers have 1 or more > occurences". It's not really your algorithm, it's your implementation of a well-known algorithm. > But usual there is some weird aspect i can't find out what i do wrong, > if you set startrange for the random numbergererator higher then 0 > values will turn up undefined i don't get it. You don't zero the right number of elements in countval. This, in turn, is because you do number=Math.floor(Math.random() * end) + start; so the numbers range from start to start+end-1. > But the timings are correct, 5 times faster for 100k of integers, and > best of all the algorithm is linear, but it purely for sorting > numbers. Quoting a factor is not very helpful. It's likely that you are doing some form of counting sort, so you can make it any number of times faster simply by sorting a larger set. Equally, you can probably make it lower by choosing a small set with a huge range. -- Ben.