More effective C + + considerations Change Library

Source: Internet
Author: User
Tags benchmark

The design of library is is a compromise process. The ideal library should be short, fast, powerful, flexible, extensible, intuitive, universally applicable, with good support, without constraints, without errors. It's not there either. Libraries that are optimized for size and speed are generally not ported. Libraries with a large number of features are not intuitive. Libraries that do not have errors are limited in their scope of use. In the real world, you can't have everything, you have to pay.

Different designers give these conditions a different priority. They sacrificed different things in the design. So generally two libraries that provide the same functionality have completely different performance characteristics.

For example, consider the iostream and stdio libraries, which are both available for C + + programmers. The iostream library has several advantages over the stdio in C (see effective C + +). For example, it is type-safe (type-safe), and it is extensible. However, in terms of efficiency, the iostream library is always inferior to the stdio, because stdio produces an execution file that is smaller and executes faster than the iostream resulting execution file.

First, consider the speed of execution. One way to master the performance difference between iostream and Stdio is to run the benchmark program with both libraries. But you must remember that benchmark can also lie. It is not only difficult to come up with a set of data that represents the typical usage of a program or library, but it is no use, unless there is a reliable way to determine what characteristics you or your customers have. But benchmark can still provide some information when it's not a way to solve a problem, so it's silly to ignore them, although it's foolish to rely entirely on benchmark.

Let's test a simple benchmark program to test only the most basic I/O functionality. The program reads 30,000 floating-point numbers from the standard input and writes them in a fixed format to the standard output. Compile-time preprocessing symbols stdio decide whether to use Stdio or iostream. If you define this symbol, you are using stdio, otherwise you will use the iostream library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.