Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34275 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2017-11-04 05:50 -0700 |
| Last post | 2017-11-04 15:16 -0700 |
| Articles | 12 on this page of 32 — 4 participants |
Back to article view | Back to comp.lang.javascript
Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 05:50 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 11:54 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 11:57 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 12:40 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:20 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 13:59 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:02 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:05 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:06 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:26 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:16 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:23 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:40 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:48 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 14:53 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 15:08 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:51 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 15:11 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:27 -0700
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 14:29 -0700
Re: Improve my sort! Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-05 20:21 +0100
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-05 16:14 -0800
Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-06 00:23 +0000
Re: Improve my sort! Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-06 02:53 +0100
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 12:02 -0700
Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 20:22 +0000
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 13:48 -0700
Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 22:08 +0000
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 15:14 -0700
Re: Improve my sort! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-04 23:12 +0000
Re: Improve my sort! jonas.thornvall@gmail.com - 2017-11-04 17:14 -0700
Re: Improve my sort! "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-11-04 15:16 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-11-05 20:21 +0100 |
| Message-ID | <2808666.PYFU5x4m9Z@PointedEars.de> |
| In reply to | #34276 |
Michael Haufe (TNO) wrote: > jonas.t...@gmail.com wrote: >> [...] > > Fix all of the errors described at <http://jshint.com/> YHBT, HTH, HAND. -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2017-11-05 16:14 -0800 |
| Message-ID | <2138ea67-886a-4187-8dda-4f1f7b1f35ed@googlegroups.com> |
| In reply to | #34305 |
Thomas 'PointedEars' Lahn wrote: > Michael Haufe (TNO) wrote: > > jonas.t...@gmail.com wrote: > >> [...] > > > > Fix all of the errors described at <http://jshint.com/> > YHBT, HTH, HAND. What does "HAND" stand for?
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-06 00:23 +0000 |
| Message-ID | <87h8u8uuf9.fsf@bsb.me.uk> |
| In reply to | #34306 |
"Michael Haufe (TNO)" <tno@thenewobjective.com> writes: > Thomas 'PointedEars' Lahn wrote: >> Michael Haufe (TNO) wrote: >> > jonas.t...@gmail.com wrote: >> >> [...] >> > >> > Fix all of the errors described at <http://jshint.com/> > >> YHBT, HTH, HAND. > > What does "HAND" stand for? My guess would be (a slightly sarcastic) "have a nice day". -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-11-06 02:53 +0100 |
| Message-ID | <2257623.6lm2GKaihZ@PointedEars.de> |
| In reply to | #34307 |
Ben Bacarisse wrote: > "Michael Haufe (TNO)" <tno@thenewobjective.com> writes: >> Thomas 'PointedEars' Lahn wrote: >>> Michael Haufe (TNO) wrote: >>> > jonas.t...@gmail.com wrote: >>> >> [...] >>> > Fix all of the errors described at <http://jshint.com/> >>> YHBT, HTH, HAND. >> What does "HAND" stand for? > > My guess would be (a slightly sarcastic) "have a nice day". Correct. -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-11-04 12:02 -0700 |
| Message-ID | <46960de0-26e1-4f9d-9631-e91b0ace5b38@googlegroups.com> |
| In reply to | #34275 |
Den lördag 4 november 2017 kl. 13:50:47 UTC+1 skrev jonas.t...@gmail.com:
> <HTML>
> <HEAD><TITLE>SORT</TITLE></HEAD>
> <BODY>
> <TABLE BGCOLOR="WHITE" BORDER=1><TH>GENERATE RANDOM NUMBERS</TH> <TR><TD>
> <FORM NAME=random onSubmit="newrandom(); return false;">
> Smallest number <input type="text" name="startrange" value="0"><br>
> Biggest number <input type="text" name="endrange" value="1000"><br>
> Values to generate <input type="text" name="xvalues" value="10000000"><P>
> <input type="submit" value="GENERATE"><P>
> VALUES TO SORT "PRINTOUT ONLY FOR ARRAY WITH LESS THEN 100000 ELEMENTS"<BR>
> <TEXTAREA NAME=sort COLS=120 ROWS=8>
> </TEXTAREA><BR>
> </FORM>
> </TD></TR></TABLE>
> <TABLE BGCOLOR="WHITE" BORDER=!>
> <TH>COMPARE SORT TIMINGS</TH>
> <TR><TD>CHOOSE SORT ALGORITHM
> <select id="mySelect" onchange="chosesort();">
> <option value="index">JT_INDEXSORT</option>
> <option value="javascript">javascript_sort</option>
> <option value="quick">QUICKSORT</option>
> </select>
> <FORM NAME=sort onSubmit="chosesort(); return false;">
> <input type=submit value="SORT"> TIME MS <input type="text" name="functime" value=""><br>
> SORTED VALUES PRINTOUT "ONLY IF ARRAY HAS LESS THEN 100000 ELEMENTS":<BR>
> <TEXTAREA TYPE=TEXT NAME=distrib COLS=120 ROWS=23>
> </TEXTAREA><BR>
> </FORM>
> </TD></TR></TABLE>
> </BODY>
> <SCRIPT LANGUAGE="Javascript">
> newrandom();
> chosesort();
> function newrandom(){
> dval=new Array();
> start=document.random.startrange.value;
> end=document.random.endrange.value;
> start=Number(start);
> end=Number(end);
> numberofvalues=document.random.xvalues.value;
> //Generate random values
> for (var i=0;i<numberofvalues;i++){
> number=Math.floor(Math.random() * end) + start;
> dval[i]=number;
> }
> if (dval.length<100000) {document.random.sort.value=dval;} else {document.random.sort.value=dval.length+" elements in array"};
> }
> function chosesort(){
> selectedsort = document.getElementById("mySelect").value;
> if (selectedsort=="index"){jtindexsort();}
> else if (selectedsort=="javascript"){javascriptNativesort();}
> else if (selectedsort=="bubble"){bubbleSort();}
> else if (selectedsort=="quick"){ quickSort(dval,0,numberofvalues);}
> if (dval.length<100000) {printout();} else {document.sort.distrib.value=dval.length+" sorted in array"};
> }
> function quickSort(arr, left, right)
> {
> var starttime = new Date().getTime();
> var i = left;
> var j = right;
> var tmp;
> pivotidx = (left + right) / 2;
> var pivot = parseInt(arr[pivotidx.toFixed()]);
> /* partition */
> while (i <= j)
> {
> while (parseInt(arr[i]) < pivot)
> i++;
> while (parseInt(arr[j]) > pivot)
> j--;
> if (i <= j)
> {
> tmp = arr[i];
> arr[i] = arr[j];
> arr[j] = tmp;
> i++;
> j--;
> }
> }
> /* recursion */
> if (left < j)
> quickSort(arr, left, j);
> if (i < right)
> quickSort(arr, i, right);
> var endtime = new Date().getTime();
> var timed = endtime - starttime;
> document.sort.functime.value=timed;
> return arr;
> }
> function javascriptNativesort(){
> var starttime = new Date().getTime();
> dval = dval.sort(sortNumber);
> var endtime = new Date().getTime();
> var timed = endtime - starttime;
> document.sort.functime.value=timed;
> }
> function sortNumber(a, b)
> {
> return a - b;
> }
> function jtindexsort(){
> var starttime = new Date().getTime();
> countval= new Array();
> //Initiate array range
> for (j=start;j<end;j++){
> countval[j]=0;
> }
> var temp;
> //Put them on correct index
> for (var i=0;i<numberofvalues;i++){
> temp=dval[i];
> countval[temp]=countval[temp]+1;
> }
> p=0;
> offset=0;
> for (var i=start;i<end;i++){
> dval.fill(i,offset,offset+countval[i]);
> offset=offset+countval[i];
> }
> var endtime = new Date().getTime();
> var timed = endtime - starttime;
> document.sort.functime.value=timed;
> }
> function printout(){
> valdist="";
> for (var j=0;j<numberofvalues;j++){
> valdist+=dval[j]+",";
> }
> document.sort.distrib.value=valdist;
> }
> </SCRIPT>
> </HTML>
When i said improve my sort i meant the speed, not the syntax.
100 millions of values ranging from 0-1000 sorted in 18 seconds.
That is what i want to improve, using javascript on my computer.
I can't see any improvements now, can you?
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-04 20:22 +0000 |
| Message-ID | <87o9oh6bgp.fsf@bsb.me.uk> |
| In reply to | #34279 |
jonas.thornvall@gmail.com writes: <snip> > When i said improve my sort i meant the speed, not the syntax. The algorithm is not yet correct. You have a bug (a different one) when start is > 0. > 100 millions of values ranging from 0-1000 sorted in 18 seconds. > That is what i want to improve, using javascript on my computer. > I can't see any improvements now, can you? I can make it a few percent faster but that may well be system specific. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-11-04 13:48 -0700 |
| Message-ID | <4ec9d774-4d48-468c-bed1-657b7bf325cb@googlegroups.com> |
| In reply to | #34282 |
Den lördag 4 november 2017 kl. 21:22:20 UTC+1 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > <snip> > > When i said improve my sort i meant the speed, not the syntax. > > The algorithm is not yet correct. You have a bug (a different one) when > start is > 0. > > > 100 millions of values ranging from 0-1000 sorted in 18 seconds. > > That is what i want to improve, using javascript on my computer. > > I can't see any improvements now, can you? > > I can make it a few percent faster but that may well be system specific. > > -- > Ben. No Ben the algorithm works just fine unless you refer to the input max value being -1, it is the random generator bug as you said. Not the sorting algorithm. The result is the same using javascript sort or quicksort.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-04 22:08 +0000 |
| Message-ID | <877ev566jc.fsf@bsb.me.uk> |
| In reply to | #34284 |
jonas.thornvall@gmail.com writes: > Den lördag 4 november 2017 kl. 21:22:20 UTC+1 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> <snip> >> > When i said improve my sort i meant the speed, not the syntax. >> >> The algorithm is not yet correct. You have a bug (a different one) when >> start is > 0. <snip> > No Ben the algorithm works just fine unless you refer to the input max > value being -1, it is the random generator bug as you said. Not the > sorting algorithm. The result is the same using javascript sort or > quicksort. Here's a screen short showing incorrect results: http://bsb.me.uk/tmp/jt-sort.png -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-11-04 15:14 -0700 |
| Message-ID | <d8b652d4-de35-46bc-92a1-6608808a9cac@googlegroups.com> |
| In reply to | #34297 |
Den lördag 4 november 2017 kl. 23:08:51 UTC+1 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > Den lördag 4 november 2017 kl. 21:22:20 UTC+1 skrev Ben Bacarisse: > >> jonas.thornvall@gmail.com writes: > >> <snip> > >> > When i said improve my sort i meant the speed, not the syntax. > >> > >> The algorithm is not yet correct. You have a bug (a different one) when > >> start is > 0. > <snip> > > No Ben the algorithm works just fine unless you refer to the input max > > value being -1, it is the random generator bug as you said. Not the > > sorting algorithm. The result is the same using javascript sort or > > quicksort. > > Here's a screen short showing incorrect results: > > http://bsb.me.uk/tmp/jt-sort.png > > -- > Ben. Well if you were intelligen you would understand it depends on the initialisation of arrays. Option 1. Try run the rng separated from the sort, you think you could manage do that change? Option 2. Press the button a second time you think your old hand could take it without it causing extreme pain?
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-04 23:12 +0000 |
| Message-ID | <871sld63kv.fsf@bsb.me.uk> |
| In reply to | #34300 |
jonas.thornvall@gmail.com writes: > Den lördag 4 november 2017 kl. 23:08:51 UTC+1 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> >> > Den lördag 4 november 2017 kl. 21:22:20 UTC+1 skrev Ben Bacarisse: >> >> jonas.thornvall@gmail.com writes: >> >> <snip> >> >> > When i said improve my sort i meant the speed, not the syntax. >> >> >> >> The algorithm is not yet correct. You have a bug (a different one) when >> >> start is > 0. >> <snip> >> > No Ben the algorithm works just fine unless you refer to the input max >> > value being -1, it is the random generator bug as you said. Not the >> > sorting algorithm. The result is the same using javascript sort or >> > quicksort. >> >> Here's a screen short showing incorrect results: >> >> http://bsb.me.uk/tmp/jt-sort.png > > Well if you were intelligen you would understand it depends on the > initialisation of arrays. > > Option 1. Try run the rng separated from the sort, you think you could > manage do that change? > > Option 2. Press the button a second time you think your old hand could > take it without it causing extreme pain? This display does not change. That's because there is a bug in the code. I really don't mind if you don't believe me. Option 3 is to fix the bug. That's what I did in the version I used to compare times. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-11-04 17:14 -0700 |
| Message-ID | <d91265c5-d3c4-4b5a-9293-64d1241f7ffe@googlegroups.com> |
| In reply to | #34302 |
Den söndag 5 november 2017 kl. 00:12:37 UTC+1 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > Den lördag 4 november 2017 kl. 23:08:51 UTC+1 skrev Ben Bacarisse: > >> jonas.thornvall@gmail.com writes: > >> > >> > Den lördag 4 november 2017 kl. 21:22:20 UTC+1 skrev Ben Bacarisse: > >> >> jonas.thornvall@gmail.com writes: > >> >> <snip> > >> >> > When i said improve my sort i meant the speed, not the syntax. > >> >> > >> >> The algorithm is not yet correct. You have a bug (a different one) when > >> >> start is > 0. > >> <snip> > >> > No Ben the algorithm works just fine unless you refer to the input max > >> > value being -1, it is the random generator bug as you said. Not the > >> > sorting algorithm. The result is the same using javascript sort or > >> > quicksort. > >> > >> Here's a screen short showing incorrect results: > >> > >> http://bsb.me.uk/tmp/jt-sort.png > > > > Well if you were intelligen you would understand it depends on the > > initialisation of arrays. > > > > Option 1. Try run the rng separated from the sort, you think you could > > manage do that change? > > > > Option 2. Press the button a second time you think your old hand could > > take it without it causing extreme pain? > > This display does not change. That's because there is a bug in the > code. I really don't mind if you don't believe me. > > Option 3 is to fix the bug. That's what I did in the version I used to > compare times. > > -- > Ben. Sorry Ben i am onto sorting strings now
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2017-11-04 15:16 -0700 |
| Message-ID | <49f14beb-719f-4eca-8e75-1c44fb0cacfc@googlegroups.com> |
| In reply to | #34297 |
Ben Bacarisse wrote: > > Here's a screen short showing incorrect results: > > http://bsb.me.uk/tmp/jt-sort.png > FAKE NEWS! ;)
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web