tree: 1c194f262644c03d50bf73b04a8477a8bd4dd4f2 [path history] [tgz]
  1. array.cxx
  2. CMakeLists.txt
  3. condition_variable.cxx
  4. deque.cxx
  5. exception.cxx
  6. forward_list.cxx
  7. future.cxx
  8. iostream.cxx
  9. Kconfig
  10. list.cxx
  11. Make.defs
  12. Makefile
  13. map.cxx
  14. multiset.cxx
  15. mutex.cxx
  16. README.md
  17. rtti.cxx
  18. semaphore.cxx
  19. set.cxx
  20. shared_ptr.cxx
  21. string.cxx
  22. string_view.cxx
  23. thread.cxx
  24. unordered_map.cxx
  25. unordered_multimap.cxx
  26. unordered_multiset.cxx
  27. unordered_set.cxx
  28. vector.cxx
  29. weak_ptr.cxx
testing/cxxsize/README.md

C++ Standard Library Code Size Testing Program

Introduction

This project provides a testing program designed to measure the code size of each class in the C++ Standard Library. Understanding the code size of various classes can help developers optimize their usage of the standard library and make informed design decisions in their applications. This program aims to provide clear insights into how much memory each component of the standard library consumes, categorized into text, data, BSS, and overall size (DEC).

Purpose

The primary goals of this project are to:

  • Analyze the memory consumption of standard library components.
  • Identify potential areas for optimization in applications that utilize these components.
  • Aid developers in making better decisions regarding the use of the C++ Standard Library depending on their application’s constraints.

Testing Platform

This program has been tested on the x4b/release branch.

C++ Compilation Configurations

  • CONFIG_HAVE_CXX
  • CONFIG_HAVE_CXXINITIALIZE
  • CONFIG_LIBCXX
  • CONFIG_LIBSUPCXX

Optimization Configurations

  • CONFIG_DEBUG_OPTLEVEL="-Os"
  • CONFIG_LTO_FULL
  • -ffunction-section
  • -fdata-section

Component-Specific Configurations

  • iostream: enable CONFIG_LIBC_LOCALE.
  • exception: enable CONFIG_CXX_EXCEPTION.
  • rtti: enable CONFIG_CXX_RTTI.

Compilation Instructions

To compile the code size testing program, use the following command:

./build.sh qemu-armv7a:nsh -j

Code Size Breakdown

The following table summarizes the code size measurements for different components in the C++ Standard Library. The sizes are measured in bytes and broken down into the following categories:

  • Text: Size of the code segment containing executable instructions.
  • Data: Size of initialized global and static variables.
  • BSS: Size of uninitialized global and static variables.
  • DEC: Total size in bytes (sum of Text, Data, and BSS).

Output Examples

Without C++ Config

   text    data     bss     dec     hex filename
 204388     300    9728  214416   34590 nuttx/nuttx

Only Basic C++ Configurations

   text    data     bss     dec     hex filename
 208100     300    9856  218256   35490 nuttx/nuttx

Compiling an Empty main Function with Basic C++ Configurations

   text    data     bss     dec     hex filename
 208132     300    9856  218288   354b0 nuttx/nuttx

Code Size Measurements

ComponentTextDataBSSDEC
basic c++371201283840
array320032
condition_variable584816608
deque411963004041544
exception3203232
forward_list411643084041512
future4350435611243972
iostream1480044043160151568
list415163084041864
map452523084045600
multiset446763084045024
mutex552816576
rtti414203084041768
semaphore135281648817808
set446443084044992
shared_ptr432043084041712
string420443084042392
string_view44800448
thread419563561242424
unordered_map476683084048016
unordered_multimap468683084047216
unordered_multiset468363084047184
unordered_set464523084046800
vector414443084041792
weak_ptr434603084041936

Conclusion

By analyzing the code size of each component in the C++ Standard Library, developers can better understand the memory implications of their usage of these classes. The details provided in this README serve as a reference point for optimizing application performance and making educated design choices. We hope you find this information valuable as you work with the C++ Standard Library.