April 2014

Common Optimizations -- Andrzej Krzemieński

Today from the desk of Andrzej:

Common Optimizations

by Andrzej Krzemieński

From the article:

Language designers, compiler and library vendors make a great effort to make your programs run faster and faster. This post is a tour of some common performance optimizations in C++.

Consider the following code that deals with std::string: ...

Parsing XML at the Speed of Light--Arseny Kapoulkine

Some high-performance techniques that you an use for more than just parsing, including this week's darling of memory management:

Parsing XML at the Speed of Light

a chapter from "The Performance of Open Source Applications"
by Arseny Kapoulkine

From the chapter:

This chapter describes various performance tricks that allowed the author to write a very high-performing parser in C++: pugixml. While the techniques were used for an XML parser, most of them can be applied to parsers of other formats or even unrelated software (e.g., memory management algorithms are widely applicable beyond parsers). ...

Optimizing software is hard. In order to be successful, optimization efforts almost always involve a combination of low-level micro-optimizations, high-level performance-oriented design decisions, careful algorithm selection and tuning, balancing among memory, performance, implementation complexity, and more. Pugixml is an example of a library that needs all of these approaches to deliver a very fast production-ready XML parser–even though compromises had to be made to achieve this. A lot of the implementation details can be adapted to different projects and tasks, be it another parsing library or something else entirely.

Continue reading...

What does [this] mean in C++? -- StackOverflow

Recently on SO:

What does "[ this ]" mean in C++?

When I was reading the Cocos2dx 3.0 API, I found something like this:

auto listener = [this](Event* event){
    auto keyboardEvent = static_cast<EventKeyboard*>(event);
    if (keyboardEvent->_isPressed)
    {
        if (onKeyPressed != nullptr)
            onKeyPressed(keyboardEvent->_keyCode, event);
    }
    else
    {
        if (onKeyReleased != nullptr)
            onKeyReleased(keyboardEvent->_keyCode, event);
    }
};

What does [this] mean? Is this new syntax in C++11?

Overload 120 is now available

overload-120.PNGOverload 120 is now available. It contains the following C++-related articles, and more:

 

Overload 120

Enforcing the Rule of Zero

Juan Alday considers how the new standards have affected a common rule.

Search with CppCheck

Martin Moene tries a more powerful code search tool.

Size Matters

 

Sergey Ignatchenko and Dmytro Ivanchykhin compare 32-bit and 64-bit programs.

Windows 64-bit Calling Conventions

Roger Orr sees how the stack organisation has changed.

Are contiguous C++ arrays really faster than Java/C# ArrayLists? -- StackOverflow

When you see anyone claim performance parity between <other language> and C++, one of the first things to look for is whether the C++ version of their test code is correctly using arrays and traversing them in order. If the test code is just doing equivalent pointer-chasing in both languages, the performance comparison is largely meaningless because the program is probably memory-bound and not properly written to use C++'s default container (vector).

Note: The question below has been modified since originally posted and now shows more reasonable numbers that demonstrate contiguous arrays are indeed faster. The comments are still enlightening to read, however.

Today on SO:

Unable to reproduce: C++ Vector performance advantages over C# List performance

At Microsoft's BUILD conference Herb Sutter explained that C++ has "Real Arrays" and C#/Java languages do not have the same or sort of.

I was sold on that. You can watch the full talk here http://channel9.msdn.com/Events/Build/2014/2-661

Here is a quick snapshot of the slide where he described this. http://i.stack.imgur.com/DQaiF.png

But I wanted to see how much difference will I make.

So I wrote very naive programs for testing, [...] Here are the results on my dell laptop with Core i7 processor:

count       C# (List<string>)   C# (ArrayList)     C++  
1000           24 ms              21 ms             7 ms      
10000         214 ms             213 ms            64 ms    
100000  2 sec 123 ms       2 sec 125 ms           678 ms

C++ and Beyond Road Show 2014 -- September 29 - October 1, Stuttgart, Germany

Today on the C++ and Beyond blog, Scott Meyers announced that registration is now open for a C&B event in Germany this fall, largely repeating the C&B December 2013 material for the benefit of those who were not able to attend the sold-out event in December.

C&B 2014: September 29 - October 1 in Stuttgart!

with Scott Meyers, Herb Sutter, Andrei Alexandrescu

Maritim Hotel, Stuttgart, Germany
September 29 - October 1, 2014

Note: The web page for the event is in German, but the seminar itself will be given in English.

From the announcement:

You can think of this event as the C&B Road Show, because the organization is a little different from how we’ve done things in the past: Most of the talks will be updated versions of the presentations we gave at C&B 2013. (See the schedule here.) If you were unable to attend C&B this past December, this is your chance to see what you missed. ... [See the] web page for C&B 2014 for all the details of this event.

This will be the only C&B in 2014, so we hope to see you in Stuttgart at the end of September for the first-ever C&B in Europe!

Native Code Performance on Modern CPUs: A Changing Landscape -- Eric Brumer

eric-brumer-build-2014.PNGThis C++ optimization talk is one of the highest-rated talks from last week's //build/ conference, and deservedly so.

Be prepared for deep content from a compiler optimizer architect, and quite a bit of subtle dry humor.

Native Code Performance on Modern CPUs: A Changing Landscape

by Eric Brumer
Compiler developer, Visual C++ team

Modern CPUs are fast. Really fast. New instructions, wider vector registers, and more powerful CPUs promise faster code. But reasoning about performance is not as it seems on the surface. This talk will dive deep into how advancements in the latest chips force some rethinking of native code performance, from the point of view of a compiler developer. The performance landscape is changing. Come see what that means.

Modern C++: What You Need to Know -- Herb Sutter

A recording of yesterday's //build/ talk by Herb Sutter is now available on Channel 9:

Modern C++: What You Need to Know

by Herb Sutter

This talk will give an update on recent progress and near-future directions for C++, both at Microsoft and across the industry. This is a great introduction to the current state of the language, including a glimpse into the future of general purpose, performance-intensive, power-friendly, powerful native programming.

From the advance description on Herb's blog:

I was asked to give a "foundational talk" about C++, and I decided that meant I should focus on addressing two questions that I get a lot these days:

  • FAQ #1 (1-2 slides): When should I use C++ compared to another language -- on all platforms in general, and on Microsoft platforms in particular?
  • FAQ #2 (lots of slides): What should I know about C++ if I’m a {Java|C#|JavaScript|Python|...} developer?

Even if you're a seasoned C++ developer, there are some nuggets and data points in the middle of the talk that I think you will find useful in your own work...