Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What known performance differences are found when using -std=gnu++11

I've been working on a Genetic Algorithm which I'd previously been compiling using g++ 4.8.1 with the arguments

CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse -march=native -std=gnu++11 

I wasn't using many of the features of c++11 and have a reasonable profiling system so I replaced literally 3-4 lines of code and had it compile without -std=gnu++11

CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse -march=native

When I ran my profiler again, I noticed that I could see ~5% performance improvement almost everywhere, except for my sort function, which was now taking about twice as long. (It's an overloaded operator< on the object)

My questions are:

What performance differences are known between the two versions, and is it expected that c++11 would be faster in newer compilers?

I'm also expecting the fact I'm using -Ofast is playing a role, am I right in my assumption?

UPDATE:

As suggested in comments I ran the tests again using with and without -march=native

// Fast sort, slightly slower in other tests
CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse -march=native -std=gnu++11  

// Fast sort, slower in other tests
CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse -std=gnu++11  

// Slow sort, slower in other tests
CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse                     

// Slow sort, fastest in other tests
CCFLAGS=-c -Wall  -Ofast -fopenmp -mfpmath=sse  -march=native

The conclusion seems to be the same that -std=gnu++11 speeds up sort drastically with a slight penalty almost everywhere else. -march=native speeds up program whenever used.

Given that sort is only called once per generation, I'll take the speed benefit of not compiling with -std=gnu++11, but I'm still very interested in what is causing these results.

I'm using the // std::sort provided from #include

like image 227
joeButler Avatar asked Feb 26 '14 20:02

joeButler


People also ask

Is Windows 11 better than Windows 10 in performance?

In short, updating to Windows 11 means a more snappy experience where apps load faster and your PC wakes from sleep with ease. Windows 10 fast, but Windows 11 is just a bit faster.

What is the difference Windows 10 and 11?

Although the two operating systems share many similarities, there are some big differences between Windows 10 and Windows 11. The newer version offers a more Mac-like aesthetic and more productivity features -- plus the chance to finally use Android apps on your computer with Windows 11.

What problems does Windows 11 have?

Issues with the Windows 11 File Explorer Windows 11 users have reported delays after clicking on File Explorer items and menus being slow to open. There are also some reports of the screen flickering in response to right-clicking on an item in File Explorer.

Is Windows 11 any good?

It's Still an Excellent Operating System Despite these qualms, there's a lot to love in Windows 11: the lovely new rounded window corners and Fluent translucent design touches, Snap Layouts, Widgets, Android App capability, Focus Sessions in the Clock app, and PC gaming improvements.


1 Answers

I am not certain why using --std=gnu++11 would make parts of the code slower. I do not use that personally (instead, I use --std=c++11). Perhaps the extra GNU features are slowing something down? More likely, the optimization hasn't caught up with the new language features yet.

As for why the sort part is faster, I have a plausible explanation:

You've enabled move semantics. Even if you don't explicitly write them yourself, if your classes are reasonably constructed, they will be generated. The "sort" algorithm probably takes advantage of them.

However, the class you've listed above doesn't seem to have much storage. However, it does not have a "swap" method, so without C++11 move semantics, the sort routine must do more work. You might look at this question and answers for more about sort and move semantics and interactions with compiler options.

like image 108
cshelton Avatar answered Oct 14 '22 03:10

cshelton