GithubHelp home page GithubHelp logo

stuianna / embeddedcodesizecomparison Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 492 KB

Compares binary code size for different C++ driver and utility architectures

Makefile 0.01% C 98.28% Assembly 1.70% C++ 0.01% Python 0.01% Shell 0.01%

embeddedcodesizecomparison's Introduction

C++ OO Method's Code Size Comparison

Compares the resulting code size for a simple UART driver and buffer utility development using four different C++ 'object orientated' methods:

  • Using pure static classes.
  • Using concrete classes.
  • Using polymorphic 'interface' classes
  • Using static polymorphism with CRTP.

Each branch contains the incremental driver development. The goal of this codebase is solely to determine the code size overhead of implementing dependency injection to support test driven development. The run-time effect of polymorphism is not taken into account.

A general look at difference between the assembly generated by each method can be found at godbolt.

Overall Code Size

The code size of the driver and utility was calculated using the 'dec' column output of arm-none-eabi-size on the .elf of the binary for each additional function added to the program. An overall analysis of the code size is:

Incremental Code Size

One Polymorphic Function (Branch: oneFunction)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1308 8 32 1348 100.00 %
UART Driver as only concrete CPP classes 1380 8 32 1420 105.34 %
UART Driver as polymorphic CPP class 1404 8 32 1444 107.12 %
UART Driver as CRTP CPP class 1496 8 32 1536 113.94 %

Two Polymorphic Functions (Branch: twoFunctions)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1364 8 32 1404 100.00 %
UART Driver as only concrete CPP classes 1468 8 32 1508 107.40 %
UART Driver as polymorphic CPP class 1504 8 32 1544 109.97 %
UART Driver as CRTP CPP class 1616 8 32 1656 117.94 %

Three Polymorphic Functions (Branch: threeFunctions)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1440 8 32 1480 100.00 %
UART Driver as only concrete CPP classes 1592 8 32 1632 110.27 %
UART Driver as polymorphic CPP class 1732 8 32 1772 119.72 %
UART Driver as CRTP CPP class 1744 8 32 1784 120.54 %

Four Polymorphic Functions (Branch: fourFunctions)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1516 8 40 1564 100.00 %
UART Driver as only concrete CPP classes 1692 8 32 1732 110.74 %
UART Driver as polymorphic CPP class 1832 8 32 1872 119.69 %
UART Driver as CRTP CPP class 1876 8 32 1916 122.50 %

Five Polymorphic Functions (Branch: fiveFunctions)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1548 8 40 1596 100.00 %
UART Driver as only concrete CPP classes 1740 8 32 1780 111.52 %
UART Driver as polymorphic CPP class 1896 8 32 1936 121.30 %
UART Driver as CRTP CPP class 1948 8 32 1988 124.56 %

Six Polymorphic Functions (Branch: sixFunctions)

Program Type Text Data BSS Total Relative Size
Empty CPP Program 864 8 32 904 NA
UART Driver as fully static CPP classes 1740 8 40 1788 100.00 %
UART Driver as only concrete CPP classes 1944 8 32 1984 110.96 %
UART Driver as polymorphic CPP class 2128 8 32 2168 121.25 %
UART Driver as CRTP CPP class 2192 8 32 2232 124.83 %

Running the Examples

  1. Clone the repository.
  2. Switch the master branch.
  3. Run make analyse to build all examples, display the code size for each step and generate a graphical output.

embeddedcodesizecomparison's People

Contributors

stuianna avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.