Re: sorting dates
JRS: In article <dchb03$rvj$1@n ews.datasync.co m>, dated Sat, 30 Jul
2005 20:54:00, seen in news:comp.lang. javascript, fox
<spamtrap@fxmah oney.com> posted :[color=blue]
>
>
>Dr John Stockton wrote:[color=green]
>> JRS: In article <dccq76$22i$1@n ews.datasync.co m>, dated Fri, 29 Jul
>> 2005 03:43:07, seen in news:comp.lang. javascript, fox
>> <spamtrap@fxmah oney.com> posted :
>>[color=darkred]
>>>
>>>comparing strings no doubt takes longer than comparing numbers.[/color]
>>
>>
>> Perhaps so. But the comparison operator should be implemented at the
>> ASM level or similar;[/color]
>
>Not relevant -- no access to asm level in js.[/color]
ASM level or similar - which includes any efficiently-compiled high
level language - is what should do the work of executing javascript
operations. We have no direct access, agreed.
[color=blue][color=green]
>> so, for strings of the length in question, ISTM
>> reasonably likely that the overall time will be dominated by other parts
>> of the routine. If it matters, it should be tested.[/color]
>
>i doubt it matters much in JS...[/color]
If there is doubt whether it matters, it should be tested; I did so.
[color=blue][color=green]
>> With 8-character strings, using the quickest test loop I know, I find
>> the loop for comparison of equal 8-character Strings to be about 10%
>> slower than that for the corresponding Numbers, loop overhead being
>> about 20%. Other browsers are likely to differ.[/color]
>
>not relevant... you didn't "get it"... and you "convenient ly" cut off "I
>used to do it in C"! This can't be done in JS... you wasted your time
>"testing" this in JS... at the "engine level" of JS's sort routine is
>STILL the character by character comparison (I checked) and whether you
>chop the string in sections of 8 or not, you still have string data types.[/color]
You miss the point. One can convert an 8-character String to Number, if
the string be a string of decimal digit characters. Sort speed of
Strings will not depend on the exact identity of the characters in them;
so one can meaningfully compare the comparison speed of Strings like
"12345678" with that of Numbers like 12345678, each being adequately
representative of the general case.
For sorting a large number of dates, one should address the question of
whether it is worthwhile to convert the dates to/from a more efficiently
sortable form before/after sorting. That conversion takes time o(N)
whereas sorting will be >o(N). Hence it is worth (slightly) converting
from String to Number for a sufficiently large number of dates, if my
result is typical.
In sorting Date Objects, things are a little different; Date Objects
store dates as Number, but a non-default Sort is needed, so here there
is the added overhead of calling (>o(N) times) a simple sort function;
however, the conversions between Date Object and Number are simpler,
involving only administrative processing.
The rest of your response is best ignored.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
JRS: In article <dchb03$rvj$1@n ews.datasync.co m>, dated Sat, 30 Jul
2005 20:54:00, seen in news:comp.lang. javascript, fox
<spamtrap@fxmah oney.com> posted :[color=blue]
>
>
>Dr John Stockton wrote:[color=green]
>> JRS: In article <dccq76$22i$1@n ews.datasync.co m>, dated Fri, 29 Jul
>> 2005 03:43:07, seen in news:comp.lang. javascript, fox
>> <spamtrap@fxmah oney.com> posted :
>>[color=darkred]
>>>
>>>comparing strings no doubt takes longer than comparing numbers.[/color]
>>
>>
>> Perhaps so. But the comparison operator should be implemented at the
>> ASM level or similar;[/color]
>
>Not relevant -- no access to asm level in js.[/color]
ASM level or similar - which includes any efficiently-compiled high
level language - is what should do the work of executing javascript
operations. We have no direct access, agreed.
[color=blue][color=green]
>> so, for strings of the length in question, ISTM
>> reasonably likely that the overall time will be dominated by other parts
>> of the routine. If it matters, it should be tested.[/color]
>
>i doubt it matters much in JS...[/color]
If there is doubt whether it matters, it should be tested; I did so.
[color=blue][color=green]
>> With 8-character strings, using the quickest test loop I know, I find
>> the loop for comparison of equal 8-character Strings to be about 10%
>> slower than that for the corresponding Numbers, loop overhead being
>> about 20%. Other browsers are likely to differ.[/color]
>
>not relevant... you didn't "get it"... and you "convenient ly" cut off "I
>used to do it in C"! This can't be done in JS... you wasted your time
>"testing" this in JS... at the "engine level" of JS's sort routine is
>STILL the character by character comparison (I checked) and whether you
>chop the string in sections of 8 or not, you still have string data types.[/color]
You miss the point. One can convert an 8-character String to Number, if
the string be a string of decimal digit characters. Sort speed of
Strings will not depend on the exact identity of the characters in them;
so one can meaningfully compare the comparison speed of Strings like
"12345678" with that of Numbers like 12345678, each being adequately
representative of the general case.
For sorting a large number of dates, one should address the question of
whether it is worthwhile to convert the dates to/from a more efficiently
sortable form before/after sorting. That conversion takes time o(N)
whereas sorting will be >o(N). Hence it is worth (slightly) converting
from String to Number for a sufficiently large number of dates, if my
result is typical.
In sorting Date Objects, things are a little different; Date Objects
store dates as Number, but a non-default Sort is needed, so here there
is the added overhead of calling (>o(N) times) a simple sort function;
however, the conversions between Date Object and Number are simpler,
involving only administrative processing.
The rest of your response is best ignored.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Comment