![]() ![]() Sorting 100K int-sized elements most likely won't spill out of your processor's cache. There's a lot of factors in play here, in no particular order. Long long int shellTime = 0, mergeTime = 0 Ĭout << "Shell Sort Time:\t " << shellTime / EXPERIMENTS << " microseconds\n" Ĭout << "Merge Sort Time:\t " << mergeTime / EXPERIMENTS << " microseconds \n" įirst: good job actually testing on real data and trying to understand why things aren't working like you expect. Typedef high_resolution_clock::time_point TimeVar #define timeNow() std::chrono::high_resolution_clock::now() #define duration(a) std::chrono::duration_cast(a).count() But why is ShellSort faster in this example when I should expect it to be slower? Am I doing something wrong? Thanks in advance! :) #include However, after running the following code, the result was MergeSort Time:22073 microseconds and ShellSort Time: 6602, which is much better. By this comment, and since the worst case time performance for Shellsort is O(n * log n), just like Mergesort, I expected Mergesort to be twice as fast than Shellsort or something like this. About Shellsort, according to Sedgewick's book (page 261) we shall see methods that are more efficient, but they are perhaps only twice as fast (if that much) except for very large N, and they are more complicated. I have implemented in C ( ) and ( ) just like Sedgewick and I created this toy example for performance comparison. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |