Click here to Skip to main content
15,889,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetEvent and WaitForSiongleObject Pin
Munchies_Matt24-Feb-15 22:57
Munchies_Matt24-Feb-15 22:57 
GeneralRe: SetEvent and WaitForSiongleObject Pin
Frankie-C24-Feb-15 23:02
Frankie-C24-Feb-15 23:02 
GeneralRe: SetEvent and WaitForSiongleObject Pin
Munchies_Matt24-Feb-15 23:06
Munchies_Matt24-Feb-15 23:06 
QuestionDeviceIoControl for drive information Pin
john563223-Feb-15 3:20
john563223-Feb-15 3:20 
QuestionQuicksort slower than mergesort... Pin
gautgaut20-Feb-15 13:22
gautgaut20-Feb-15 13:22 
AnswerRe: Quicksort slower than mergesort... Pin
David Crow20-Feb-15 15:43
David Crow20-Feb-15 15:43 
GeneralRe: Quicksort slower than mergesort... Pin
gautgaut21-Feb-15 0:56
gautgaut21-Feb-15 0:56 
GeneralRe: Quicksort slower than mergesort... Pin
Stefan_Lang23-Feb-15 20:50
Stefan_Lang23-Feb-15 20:50 
If your implementation "only" takes about 3 times as long as the stdlib qsort, then you can be reasonably sure that, technically, you did it correctly.

As for why your program takes longer, there are quite a number of things that can go wrong in performance optimization. A good start would be avoiding shortcuts and explicit optimization, even if it may sound counter-intuitive. The compiler is exceptionally good at optimizing code without your help, but to do this efficiently, it needs to see the "real" code, not some byte manipulation that it can't make heads or tails of.

One example is your #define: all it does is accessing array members, but all the compiler sees is some weird pointer arithmetic. Do leave the compiler arithmetic to the compiler, and you'll find that at the very least you'll get more readable code at no performance loss, and maybe you'll even see an improvement. I think I understand what you use this define for, but if I'm right, all you really need is a typecast from void* to int* (or pointer to whatever element type you're using)

Another issue may be the various helper functions you're calling: without the actual type information, these functions may be very inefficient. E. g. a function to swap two ints only requires a handful of assembler instructions. A function to swap two arrays of n bytes, where n is a run time variable, requires about three to five times as much.

You could check your compiler's aqssembler output to see what it makes of your code. Try different variants to find out what the compiler makes of it. Maybe that can give you some insight into what is causing the performance issue.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

GeneralRe: Quicksort slower than mergesort... Pin
gautgaut26-Feb-15 6:46
gautgaut26-Feb-15 6:46 
Questiondecision tree Pin
Member 1146482519-Feb-15 7:21
Member 1146482519-Feb-15 7:21 
AnswerRe: decision tree Pin
jeron119-Feb-15 7:34
jeron119-Feb-15 7:34 
QuestionRe: decision tree Pin
David Crow19-Feb-15 8:52
David Crow19-Feb-15 8:52 
QuestionSimple AES Pin
Member 1065708319-Feb-15 3:46
Member 1065708319-Feb-15 3:46 
AnswerRe: Simple AES Pin
jeron119-Feb-15 4:22
jeron119-Feb-15 4:22 
GeneralRe: Simple AES Pin
Member 1065708319-Feb-15 14:37
Member 1065708319-Feb-15 14:37 
GeneralRe: Simple AES Pin
enhzflep19-Feb-15 17:53
enhzflep19-Feb-15 17:53 
GeneralRe: Simple AES Pin
Member 1065708319-Feb-15 18:25
Member 1065708319-Feb-15 18:25 
GeneralRe: Simple AES Pin
enhzflep19-Feb-15 18:29
enhzflep19-Feb-15 18:29 
GeneralRe: Simple AES Pin
Member 1065708319-Feb-15 20:38
Member 1065708319-Feb-15 20:38 
GeneralRe: Simple AES Pin
enhzflep19-Feb-15 20:52
enhzflep19-Feb-15 20:52 
GeneralRe: Simple AES Pin
Member 1065708319-Feb-15 23:21
Member 1065708319-Feb-15 23:21 
GeneralRe: Simple AES Pin
enhzflep20-Feb-15 1:00
enhzflep20-Feb-15 1:00 
GeneralRe: Simple AES Pin
Member 1065708320-Feb-15 2:05
Member 1065708320-Feb-15 2:05 
QuestionMicrosoft foundation class Pin
Kamlendra Chandra18-Feb-15 0:30
Kamlendra Chandra18-Feb-15 0:30 
AnswerRe: Microsoft foundation class Pin
Jochen Arndt18-Feb-15 1:10
professionalJochen Arndt18-Feb-15 1:10 

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.