tree: b13df5ca9216d02659d069bf92ef5308cccba048 [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/cxx/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
array160016
condition_variable14400144
deque24008248
exception160016
forward_list14408152
future392048724040
iostream66192120170468016
list52808536
map4256084264
multiset3680083688
mutex11200112
rtti2208082216
semaphore130012841392
set3616083624
shared_ptr46408472
string_view43200432
string1376081384
thread104048721160
unordered_map6616006616
unordered_multimap5864005864
unordered_multiset5816005816
unordered_set5432005432
vector45608464
weak_ptr62408632

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.