1

I was testing and profiling one of my applications, which I run as a docker container. During my testing I noticed that the application was running faster when executed directly in my host, respect to as a docker container. So, trying to isolate the root cause of this issue (like for example performance hits by using volumes), I wrote this simple example application:

test.cpp

#include <iostream>

void __attribute__ ((noinline)) task()
{
        for (std::size_t i {0}; i < 1000000000; ++i)
        {
                double a { static_cast<double>(rand())/RAND_MAX };
                double b { static_cast<double>(rand())/RAND_MAX };

                double c { a * b };

                c += 1;
        }

}

int main(int argc, char** argv)
{
        task();
}

Which I compiled with:

$ g++ -pg -O3 -o test test.cpp

After running the resulting application, I obtained this result from gprof:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.70      0.36     0.36                             task()
  0.00      0.36     0.00        1     0.00     0.00  _GLOBAL__sub_I__Z4taskv

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 2.76% of 0.36 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.36    0.00                 task() [1]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [15]
[9]      0.0    0.00    0.00       1         _GLOBAL__sub_I__Z4taskv [9]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

   [9] _GLOBAL__sub_I__Z4taskv [1] task()

So, the task() function took around 0.36s.

Now, I want to try running the same application in a docker container. As my host OS is ubuntu 18.04, I used ubuntu:18.04 as a base image. I used this Dockerfile:

Dockerfile

FROM ubuntu:18.04

# Install g++ and gcc
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    g++ \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Copy the test source file to /test/
RUN mkdir /test
COPY ./test.cpp /test/

# Compile the test application
WORKDIR /test
RUN g++ -pg -O3 -o test test.cpp

I build the image with:

$ docker image build -t docker-test .

and then run it with:

$ docker container run -ti --rm docker-test

Once there I ran the test application and obtainer this result from gprof:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.70      0.58     0.58                             task()
  0.00      0.58     0.00        1     0.00     0.00  _GLOBAL__sub_I__Z4taskv

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 1.71% of 0.58 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.58    0.00                 task() [1]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [15]
[9]      0.0    0.00    0.00       1         _GLOBAL__sub_I__Z4taskv [9]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

   [9] _GLOBAL__sub_I__Z4taskv [1] task()

So, the same task() function took this time around 0.58 seconds, almost 2x slower respect to running it in the host.

Why is the application running slower in the docker container? Am I doing something wrong? Or is there a way to improve the performance?

  • 2
    Are you using the same `g++` version in both computers? I wonder if it's anything to do with `rand()` (if it's using `dev/random` rather than `dev/urandom` - or if the platform's RNG exposed through Docker is suboptimal). What happens if you remove the `rand()` and perform some expensive IEEE-754 operations instead? – Dai Jun 06 '20 at 00:04
  • What happens if you copy the binary into the container, instead of copying the source and recompiling it? – Joseph Sible-Reinstate Monica Jun 06 '20 at 00:04
  • 2000000000 call to `rand` performed in only 0.36s? It seems very suspicious! It means that 5.6 G calls/s are performed which is very surprising since the GCC `rand` implementation [should takes more than 3 cycles and is intrinsically sequential](https://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/random_r.c;hb=glibc-2.31#l353). Thus, either you have an unrealistic processor that run at more than 16.7 GHz, or the compiler removed the rand calls because they are not actually needed and what you measure is probably noise! See [here](https://stackoverflow.com/q/40122141) for more information. – Jérôme Richard Jun 06 '20 at 11:34

1 Answers1

2

Thank you all for your comments. As Jérôme Richard mentioned the result of my test was indeed suspicious. Also, I ran the same test multiple time the following days and I obtained different results, most of them with an execution time equal to the one obtained in the host; so I was probably running my test in parallel with other docker container running at the same time which were consuming a lot of CPU (I was other heavy tests in the same host at that time).

So, I decided to start again, and this time I took a actual piece of code of the application I was trying to optimize and repeat my test. This is the code I used this time:

app.h

#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <assert.h>
#include <numeric>
#include <mutex>

template<typename T>
class Filter {
public:
    Filter(std::size_t numberChannels);

    void process(const std::vector<T>& input, std::vector<T>& outData);
private:
    std::size_t          numCh;
        std::size_t          order;
        double               gain;
        std::vector<double>  a;
        std::vector<double>  b;
        std::size_t          currentBlockIndex;
        std::size_t          currentIndex;
        std::vector<double>  x;
        std::vector<double>  y;
};

template<typename T>
void writeVectToFile(const std::vector<T>& v, const std::string& fileName);

app.cpp

#include "app.h"

const std::size_t numSamples { 1000000 };

template<typename T>
Filter<T>::Filter(std::size_t numberChannels)
:
    numCh             { numberChannels      },
    order             { 4                   },
    gain              { 1                   },
    a                 { 1.0, -3.74145562, 5.25726624, -3.28776591,  0.77203984 },
    b                 { 5.28396689e-06, 2.11358676e-05, 3.17038014e-05, 2.11358676e-05, 5.28396689e-06 },
    currentBlockIndex { order               },
    currentIndex      { 0                   },
    x                 ( (order +1) * numCh  ),
    y                 ( (order +1) * numCh  )
{
}

template<typename T>
void __attribute__ ((noinline)) Filter<T>::process(const std::vector<T>& inputData, std::vector<T>& outputData)
{
    if (currentIndex == order)
        currentIndex = 0;
    else
        ++currentIndex;

    std::vector<double>::iterator           xCh    { x.begin() + currentIndex };
    std::vector<double>::iterator           yCh    { y.begin() + currentIndex };
    std::vector<double>::const_iterator     aIt    { a.begin()                };
    std::vector<double>::const_iterator     bIt    { b.begin()                };
    typename std::vector<T>::const_iterator dataIt { inputData.begin()        };

    for (std::size_t ch{0}; ch < numCh; ++ch, xCh += order + 1, yCh += order + 1)
    {
        *xCh = static_cast<double>(*dataIt++);
        *yCh= *bIt * *xCh;
    }

    std::size_t previousIndex { currentIndex };
    std::vector<double>::const_iterator xChPrev;
    std::vector<double>::const_iterator yChPrev;

    for (std::size_t t{1}; t < order + 1; ++t)
    {
        if (previousIndex == 0)
            previousIndex = order;
        else
            --previousIndex;

        yCh     = y.begin() + currentIndex;
        xChPrev = x.begin() + previousIndex;
        yChPrev = y.begin() + previousIndex;
        ++aIt;
        ++bIt;

        for (std::size_t ch{0}; ch < numCh; ++ch, yCh += order + 1, xChPrev += order + 1, yChPrev += order + 1)
        {
            *yCh += *bIt * *xChPrev - *aIt * *yChPrev;
        }
    }

    yCh = y.begin() + currentIndex;
    typename std::vector<T>::iterator outIt(outputData.begin());
    for (std::size_t ch{0}; ch < numCh; ++ch, yCh += order + 1)
    {
        *yCh /= a[0];
        *outIt++ = static_cast<T>(*yCh * gain);
    }
}

template<typename T>
void writeVectToFile(const std::vector<T>& v, const std::string& fileName)
{
    std::ofstream outFile(fileName);
    for (const auto &e : v) outFile << e << "\n";
}

int main(int argc, char* argv[])
{
    const std::size_t numberChannels { 2000 };

    std::vector<int32_t> inputData  ( numberChannels );
    std::vector<int32_t> outputData ( numberChannels );
    std::vector<int32_t> sampleIn   ( numSamples     );
    std::vector<int32_t> sampleOut  ( numSamples     );

    // Create filter object
    Filter<int32_t> f(numberChannels);

    // Send 'numSamples' random values through the filter
    for(std::size_t i {0}; i < numSamples; ++i)
    {
        // Generate random samples
            for (auto &d: inputData)
            d = static_cast<int32_t>( (static_cast<double>(rand())/RAND_MAX) * (2147483647.0) );

        f.process(inputData, outputData);

        // Get the first input and output value
        // They will be use to validate the result
        sampleIn[i]  = inputData[0];
        sampleOut[i] = outputData[0];
    }

    // Write the result to disk
    writeVectToFile( sampleIn,  "x.dat" );
    writeVectToFile( sampleOut, "y.dat" );
}

I compiled with this Makefile:

Makefile

CXX = g++
CXXFLAGS = -Wall -g -O3 -pg

%.o: %.cpp
        $(CXX) -c -o $@ $< $(CXXFLAGS)

app: app.o
        $(CXX) -o $@ $^ $(CXXFLAGS)

clean:
        rm -rf app app.o *.dat gmon.out

And got this result:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.11     19.81    19.81                             Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)
  0.05     19.82     0.01                             void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  0.00     19.82     0.00        1     0.00     0.00  _GLOBAL__sub_I_main

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.05% of 19.82 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     99.9   19.81    0.00                 Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]      0.1    0.01    0.00                 void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [2]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [19]
[10]     0.0    0.00    0.00       1         _GLOBAL__sub_I_main [10]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

  [10] _GLOBAL__sub_I_main (app.cpp) [2] void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [1] Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)

Around 20 seconds to call the method Filter<T>::process 1e6 times.

Then I crate a docker image with (this time I also copied the binary file generated in the host):

Dockerfile

FROM ubuntu:18.04

# Install g++ and gcc
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy the test source file to /test/
RUN mkdir /test
COPY * /test/

# Copy the binary used for testing in the host
RUN mkdir /test-host
COPY ./app /test-host/app

# Compile the test application
WORKDIR /test
RUN make clean && make

I built the image with:

$ docker image build -t docker-test --no-cache .

And runnit with:

docker container run -ti --rm docker-test

and I got:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.11     21.71    21.71                             Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)
  0.05     21.72     0.01                             void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  0.00     21.72     0.00        1     0.00     0.00  _GLOBAL__sub_I_main

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.05% of 21.72 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0   21.71    0.00                 Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]      0.0    0.01    0.00                 void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [2]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [19]
[10]     0.0    0.00    0.00       1         _GLOBAL__sub_I_main [10]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

  [10] _GLOBAL__sub_I_main (app.cpp) [2] void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [1] Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)

I obtained almost the same result using both the binary compiled in the host, and the one compiled i the docker image.

This time I obtainer almost the same result running in the host vs running in the container (around 20 seconds in both cases). So, I don't see any performance impact when running in a container.

The g++ compiler in my host was:

$ g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The g++ compiler in my container was:

# g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm using this docker version:

$ docker version
Client: Docker Engine - Community
 Version:           19.03.7
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        7141c199a2
 Built:             Wed Mar  4 01:22:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.7
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       7141c199a2
  Built:            Wed Mar  4 01:21:08 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683