C++ timers

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: stevf
one of the sorts I perform in this test is a merge sort based on an unordered list. The sort and list code was provided to me but it certainly is nothing special. That sort is slightly faster that the quick sort on an array. The data sorted is the same for each run as I loop through all the sorts 10 times and use the value of my loop counter for the seed. It is just the STL list that is horrible. I am going to try a few other things from the STL and see what happens. I have done far more than the assignment requires already but I am having fun throwing extra things in there and seeing what happens


Also, any suggestions for more tests? I was required to do a bubble, insertion, selection, quick, and merge using the code that was provided. I have added a gnome sort (just because of the silly name) and the STL sort. Was going to cast one set to double and run that through one or two of the sorts to see if that makes a difference. May add radix to it too. These should often be worst case scenarios as the data is random

If the values you are sorting are integers, try Radix sort.

As far as more experiments, consider trying each of your sorting algorithms with and without compiler optimizations.

Speaking of compiler optimizations, STL sort() would be slow if the comparison operator isn't inlined -- make sure it is declared in a header file somewhere as 'inline' and ensure that your compiler is properly inlining the call.
 

stevf

Senior member
Jan 26, 2005
290
0
0
thanks for the suggestions - will try a few of them out. One question though. How do I inline something from the STL? Is it as simple as overloading the operator to make it inline?


Thanks
 

Sc4freak

Guest
Oct 22, 2004
953
0
0
Short answer is that you don't. The "inline" keyword is only a suggestion. Your compiler is free to ignore it. MSVC has the "__forceinline" keyword, which is a slightly stronger suggestion, but the compiler is still free to ignore it.

But I'd say that any compiler with half a brain will automatically inline trivial functions like a comparison operator. If you enable global optimisations, the compiler will be able to perform cross-module inlining so you don't need to fiddle about with header files. In a lot of cases, the compiler will have better judgement than you do.
 

stevf

Senior member
Jan 26, 2005
290
0
0
thanks - that is what I thought - the compiler ignores inline whenever it feels like it
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Sc4freak
Short answer is that you don't. The "inline" keyword is only a suggestion. Your compiler is free to ignore it. MSVC has the "__forceinline" keyword, which is a slightly stronger suggestion, but the compiler is still free to ignore it.

But I'd say that any compiler with half a brain will automatically inline trivial functions like a comparison operator. If you enable global optimisations, the compiler will be able to perform cross-module inlining so you don't need to fiddle about with header files. In a lot of cases, the compiler will have better judgement than you do.

Like everything, this depends on the compiler. I predominately use gcc, so I know its inlining preferences well. The trick to get GCC to inline is to make sure you're on -O2 or better, and define the entire function in a header file -- don't expect GCC to inline a function from myFile1.C into myFile2.C.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |