Click to See Complete Forum and Search --> : QSort speed


Quell
April 30th, 2004, 08:11 AM
Hello.
i use qsort, to sort an array of 1000 random integers(from 0-to 10000 each)..and it gives me the result of 0.25 milliseconds....is this a normal time or did i screw up with timing?
thx in advance

yiannakop
April 30th, 2004, 08:20 AM
0.25 milliseconds??? How do you count such a small ammount of time?

Quell
April 30th, 2004, 08:39 AM
i use query performence frequency to do this......
and how about 20 millysecond for bubble sort, same array....

yiannakop
April 30th, 2004, 08:46 AM
Quick sort has time complexity O(nlog(n)) and bubble sort has, O(n^2) though, so for 1000 numbers the quick sort SHOULD (theoretically) be almost 150 times faster than the bubble sort.

yiannakop
April 30th, 2004, 08:47 AM
Ah, and as I can see that (almost) agrees with your results :thumb: .

Milano
April 30th, 2004, 07:40 PM
Originally posted by Quell
i use query performence frequency to do this......
and how about 20 millysecond for bubble sort, same array....
What is Query Performance Frequency and how to use it ? May I ask ? ^,^

Thanks,

Regards,
-Milano

Yves M
May 1st, 2004, 03:59 AM
Check the Profiling FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=291294)

Milano
May 1st, 2004, 04:56 AM
Originally posted by Yves M
Check the Profiling FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=291294)
Thanks Yves a lot,

Regards,

-Milano

Quell
May 1st, 2004, 07:18 AM
Hey.
For my problem above wiht the numbers fo 19 and 0.25 ms...they changed from 6 and 3 ms respectivly...i am not sure what i did and why it happended.....here is a list of changes that i made....
-the speed test is inside of 2 functions....i changed the return type of the functin (from void to double on both).
-i use a parameter list instead of global variables from main.
-i used typdefenition for stuff like unsinged short -> US.
i do wanna change evrything back becuase of amount of code needed to be changed.
Can anyone give me a theoretical unswer to the reason for above change and a little explanation plx.
thx in advance.
P.S. Mialno, the link that was givven has several testes posibiliies...i think that the QueryPerformance counter is the best...becuase the RDSTC(something like that) is not supported on all cpus....and Query is much easier to use.
Just an opinion.

Milano
May 2nd, 2004, 01:16 AM
Originally posted by Quell
Hey.
For my problem above wiht the numbers fo 19 and 0.25 ms...they changed from 6 and 3 ms respectivly...i am not sure what i did and why it happended.....here is a list of changes that i made....
-the speed test is inside of 2 functions....i changed the return type of the functin (from void to double on both).
-i use a parameter list instead of global variables from main.
-i used typdefenition for stuff like unsinged short -> US.
i do wanna change evrything back becuase of amount of code needed to be changed.I amnot quite following you...What exactly are you asking ? Does the speed you mean get faster when there is such a change ? I don't know whether you are implementing qsort algorithm for its complexity purpose only or something else...Are you using it with template for dealing with different runtime types input from the users ?
P.S. Mialno, the link that was givven has several testes posibiliies...i think that the QueryPerformance counter is the best...becuase the RDSTC(something like that) is not supported on all cpus....and Query is much easier to use.
Just an opinion. Thanks a lot, I see your points here....(lol) Thanks....

-Milano

Quell
May 2nd, 2004, 06:43 AM
the above list of changes that i descibed changedd my result on the speed test.
What is the cause of this change?
That is what i was trying to ask before...

Milano
May 2nd, 2004, 09:41 AM
First of all, i have to say that I don't have any special skills in compiler optimization techniques, tick counts, hardware architecture such and such, and hence what i posted here might turn out incorrect, and in case if that is true (incorrect), i hope I will be corrected immediately.......:smile:
Originally posted by Quell
-the speed test is inside of 2 functions....i changed the return type of the functin (from void to double on both).
I think the return type's change doesnot mean anything in this case, it won't make any change to your speed, but I think it is a good idea to put your speed test right before and after the operation you want to check. Speed test code must also be executed and that I think also consumes some time.
Originally posted by Quell
-i use a parameter list instead of global variables from main.About which kinds of variables are to be initialized first in a program, i am not sure, and forgot already ...(lol), true, but I still remember that there is a thread right on this board where galathaea already stated about static variable initialization in a certain program which I think you should do a search for its information. That was a good article I like...
Originally posted by Quell
-i used typdefenition for stuff like unsinged short -> US.
inline_s, define_s are all good for increasing speed of the program...

<I actually intended to post right at the time you posted but I had my dinner waiting...(lol)>

Hope that could be any help,

Regards,
-Milano

Quell
May 2nd, 2004, 10:12 AM
hmm...thx for you answer but i am still not sure...what changed the speed of my test? i do not think it is the return type cuz the test is INSIDE the function itself.
and i don't think it is the typedefinition..cuz it just redifines the types....does not slow down/speed up any stuff, does it?
so since my parameters are a bunch of array then they acess time to them will have to change when i put them from global to parameters...but why did one of my time increaaase(bubble sort) and qsort decreased?

Milano
May 2nd, 2004, 10:42 AM
Originally posted by Quell
hmm...thx for you answer but i am still not sure...what changed the speed of my test? i do not think it is the return type cuz the test is INSIDE the function itself.
(lol) Are you putting me on ? I mean you went on this way, but why you turn around to look for another way...and ye, the return type does nothing here, i also think so...
and i don't think it is the typedefinition..cuz it just redifines the types....does not slow down/speed up any stuff, does it?macro defines are always good in some simple cases !!!
This is what I absolutely believe...
so since my parameters are a bunch of array then they acess time to them will have to change when i put them from global to parameters...but why did one of my time increaaase(bubble sort) and qsort decreased?
bubble sort and qsort are absolutely different talks, they have complexities...




-------------------------------------------------------
My signature: i don't like that egg anymore.
No fight is needed from you...

I dreamt i was a turtle trying to get an egg. But there was a kid who stopped me from getting that egg. So i swam at the opposite side of the beach and tricked the kid into following me and them swam to the egg quickly and grabbed it and swam away.
Later that day i needed to take my time even when i felt i hadn't got much time. Then made myself a few extra bucks for taking that time and a weekend job to make more money.

Ecuador -=[NM]=-
May 2nd, 2004, 10:44 AM
sorry for this dumb question ( although I heard there ain't stupid questions, just stupid answers :D ), but doesn't quick sort base on the insertion sort engine ? Well, what I wanted to say is, that I have written several sort engines basing on insertion sort, and phew, used together with vectors this thing is fu... fast. If someone is interested into a piece of code, lemme know...

Greets


ecu@dor

Quell
May 2nd, 2004, 10:54 AM
i am not putting you on...i guess my question was a little broad....but it was why does the speed change the way it does, form 3, 6 to 0.5 and 20......respectivly...
i coudl understand if all went one or another way, that is ok....but since one time decreased and one increased.....(qsort increase).....
So my question changes a bit now:
why does qsort's time decreased.....? does it work in a way so that if i use local variables are in parameters(instead of global) it workes faster or somthing?
i just remade my prog step by step and the change is in the parameters....

Milano
May 2nd, 2004, 11:09 AM
(lol),....
You also make me konfused...I understood what you meant thoroughly, qsort is actually nothing special, i also believe you know for sure that there is also a really long long fight on this board about qsort, if you dont care to spend some time doing a search, I actually have no feelings left when someone is also trying to bring up something like how qsort works to irritate me, it means nothing really, and from this, i realized how i feel about qsort...what i said was just to support and help you out with what i think i know.
Bytheway, you also made a correct guess, I guess...lol...

---------------------------------------------------------------------------
My signature: i don't like that egg anymore.

I dreamt i was a turtle trying to get an egg. But there was a kid who stopped me from getting that egg. So i swam at the opposite side of the beach and tricked the kid into following me and them swam to the egg quickly and grabbed it and swam away.
Later that day i needed to take my time even when i felt i hadn't got much time. Then made myself a few extra bucks for taking that time and a weekend job to make more money.