Answer the question
In order to leave comments, you need to log in
Quick sort works in c# for some reason faster than in c++. Shouldn't it be the other way around?
Wrote qsort in c++ and exactly the same code in c#. As a result, the same code in c++ runs several times slower than in c#. For example, in C++ it sorts a million elements in 1.5 seconds (this is with pointers, and if you use vectors in general, 6 seconds), and in c# in about 0.5 seconds. Why is that, because c++ should work faster than c#? Both sortings are written in VS 13. If necessary, I'll throw off the code.
Answer the question
In order to leave comments, you need to log in
First, make sure you compile to c++ in the release.
Secondly, show your C++ code, I'm sure that I can show you very quickly what slows you down and at least get the same speed.
Have you looked at the sizes of the files? C# turned out to be many times smaller? Are you sure you haven't turned the optimizations all the way up? Or did VS for C# not unscrew itself? C++ is not for children and morons under 18 years old. The calculation is that the developer himself knows everything and sets everything up himself. Unscrew /O3 and stuff. Or compile to g++ with -O3. There are releases of varying degrees of debugging. Compiled on default settings and panic, as if the system was overthrown. If you know something, it does not mean that no one knows it. Configs, flags? Where is it all?
Why should C++ be faster than C#?
At a minimum, C#'s allocator is more efficient, when it needs to allocate memory, it simply shifts the occupied memory pointer up the heap.
If there are only a million elements, and they are integer, then the GC never even got to the point.
Shouldn't. It is known for certain that there are things that work faster in Java than in C ++ or C (especially if programmed "stupidly", without ingenious manual optimizations and hacks based on taking into account the low-level features of the machine), and even faster in Scala. C# in this context, one might say, is the same Java/Scala. I wouldn’t even be surprised if there are tasks in which performance, for example, PHP will lead.
And if you compare with the library?
www.cplusplus.com/reference/cstdlib/qsort
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question