Click here to Skip to main content
16,007,163 members
Home / Discussions / C#
   

C#

 
AnswerRe: Issue with Crystal Report Pin
Abhinav S3-Jun-10 2:21
Abhinav S3-Jun-10 2:21 
GeneralRe: Issue with Crystal Report Pin
spankyleo1233-Jun-10 23:04
spankyleo1233-Jun-10 23:04 
Questiongridview rows stored in database Pin
jadhavShubhangi3-Jun-10 1:23
jadhavShubhangi3-Jun-10 1:23 
AnswerCross Post Pin
Not Active3-Jun-10 1:59
mentorNot Active3-Jun-10 1:59 
QuestionInsertions sort reversed - optimize Pin
bolikej3-Jun-10 0:03
bolikej3-Jun-10 0:03 
GeneralRe: Insertions sort reversed - optimize Pin
harold aptroot3-Jun-10 1:00
harold aptroot3-Jun-10 1:00 
GeneralRe: Insertions sort reversed - optimize Pin
bolikej3-Jun-10 1:21
bolikej3-Jun-10 1:21 
GeneralRe: Insertions sort reversed - optimize [modified] Pin
harold aptroot3-Jun-10 1:42
harold aptroot3-Jun-10 1:42 
The thing I found is ..
edit: wait a minute I'll figure this out..

There is something else though, which is the algorithm. And I don't mean that you should use a different kind of sort, but I mean the "search backwards" part. This backwards searching only helps for certain inputs, as you probably know. Since the first part is sorted, you could do a binary search. It doesn't affect the "big O" of course but for random inputs it would work better on average since less time would be spent searching for the correct place, assuming the array is big enough to hide the Nasty Constant hidden by the big O.
On the other hand, insertion sort would be the wrong choice for random inputs.
It could be worth investigating, though.


edit2: ok back to this "1 thing".

The original "copy loop" is
for (int i = h; i > v + 1; i--)
{
    arr[i] = arr[i - 1];
}

The new loop would be:
for (int i = h - 1; i > v; i--)
{
    arr[i + 1] = arr[i];
}

And I'll have to conclude that it could be faster, but the CLR is a bit of an idiot, especially in debug mode which is the only think I can quickly test (it does things like storing the result of the loop condition on the stack - presumably for the debugger to know the result of the comparison). In C++ or C this kind of trick would work (if the compiler didn't think of it first) and it might work for C# in release mode.
I'll run some tests.
Edit: yes, it is approximately 4% faster, with array length 1k. 5.5% with array length 10k.
Edit2: this result may be insignificant.

There may also be a way to avoid array-bounds checks (well, 1 per iteration max anyway), I'll look into it.

Edit: no, there isn't.

modified on Thursday, June 3, 2010 8:16 AM

GeneralRe: Insertions sort reversed - optimize Pin
harold aptroot3-Jun-10 2:15
harold aptroot3-Jun-10 2:15 
GeneralRe: Insertions sort reversed - optimize Pin
bolikej3-Jun-10 2:31
bolikej3-Jun-10 2:31 
QuestionBest performance LAN communication for a Server/Client application Pin
teknolog1232-Jun-10 22:58
teknolog1232-Jun-10 22:58 
AnswerRe: Best performance LAN communication for a Server/Client application Pin
#realJSOP3-Jun-10 1:50
professional#realJSOP3-Jun-10 1:50 
QuestionCreating Events Pin
Roger Wright2-Jun-10 22:37
professionalRoger Wright2-Jun-10 22:37 
AnswerRe: Creating Events Pin
Abhinav S2-Jun-10 23:05
Abhinav S2-Jun-10 23:05 
AnswerRe: Creating Events Pin
OriginalGriff3-Jun-10 0:45
mveOriginalGriff3-Jun-10 0:45 
GeneralRe: Creating Events Pin
Roger Wright3-Jun-10 4:08
professionalRoger Wright3-Jun-10 4:08 
AnswerRe: Creating Events Pin
DaveyM693-Jun-10 1:38
professionalDaveyM693-Jun-10 1:38 
GeneralRe: Creating Events Pin
Roger Wright3-Jun-10 4:09
professionalRoger Wright3-Jun-10 4:09 
QuestionSystem.DBNull returned for whitespace strings Pin
GDavy2-Jun-10 22:07
GDavy2-Jun-10 22:07 
AnswerRe: System.DBNull returned for whitespace strings Pin
Pete O'Hanlon2-Jun-10 23:30
mvePete O'Hanlon2-Jun-10 23:30 
GeneralRe: System.DBNull returned for whitespace strings Pin
GDavy2-Jun-10 23:59
GDavy2-Jun-10 23:59 
GeneralRe: System.DBNull returned for whitespace strings Pin
Pete O'Hanlon3-Jun-10 0:23
mvePete O'Hanlon3-Jun-10 0:23 
QuestionProblem reading multiple bytes from serialport Pin
myreki2-Jun-10 21:35
myreki2-Jun-10 21:35 
AnswerRe: Problem reading multiple bytes from serialport Pin
Luc Pattyn3-Jun-10 2:14
sitebuilderLuc Pattyn3-Jun-10 2:14 
QuestionNotifyPropertyChanged and ReadValue() not working Pin
Mycroft Holmes2-Jun-10 21:20
professionalMycroft Holmes2-Jun-10 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.