<div dir="ltr"><div dir="ltr"><div style="font-family:courier new,monospace;font-size:large" class="gmail_default">Hi Cyril,</div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default"><br></div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default"><a href="https://godbolt.org/z/vv3xWP">https://godbolt.org/z/vv3xWP</a>   generated 467 lines of assembler with clang trunk and -O0 (on Linux, I suppose), versus 58 lines for the function pointer.</div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default"><br></div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default">With -O2 it was 76 lines vs 20 lines.</div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default">(Nine lines are always used to initialize iostream and set up its destruction)</div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default"><br></div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default">There may be extra code linked in from libc++ for std::function.<br></div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default"><br></div><div style="font-family:courier new,monospace;font-size:large" class="gmail_default">Csaba</div><div class="gmail_default" style="font-family:courier new,monospace;font-size:large"><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 8 Jan 2021 at 11:45, Cyril Makloufi via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div dir="ltr">
<p class="gmail-m_-350041447199119474ImprintUniqueID"></p>
<div id="gmail-m_-350041447199119474divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">Hello,</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont"><br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">When using std::function instead of function pointer (see the sample of code) on Mac, we get a huge difference between size of generated binary (80ko when using function pointer and 157ko whit
 std::function).</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">I use Xcode to build debug with -O0 -std=gnu++14 and libc++.</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">It doesn't seem to have the same result on windows or linux.</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">Is it something normal ?</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont"><br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">Here's the code sample :</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont"><br>
</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(252,106,93);background-color:rgb(31,31,36)">
<span style="color:rgb(253,143,63)">#include </span><iostream></p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(252,106,93);background-color:rgb(31,31,36)">
<span style="color:rgb(253,143,63)">#include </span><functional></p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36);min-height:14px">
<br>
</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36);min-height:14px">
<br>
</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36)">
<span style="color:rgb(252,95,163)"><b>int</b></span> <span style="color:rgb(65,161,192)">main</span>(<span style="color:rgb(252,95,163)"><b>int</b></span> argc,
<span style="color:rgb(252,95,163)"><b>const</b></span> <span style="color:rgb(252,95,163)"><b>char</b></span> * argv[]) {</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36)">
    <span style="color:rgb(208,168,255)">std</span>::<span style="color:rgb(208,168,255)">function</span><<span style="color:rgb(252,95,163)"><b>void</b></span>()> f = [](){<span style="color:rgb(208,168,255)">std</span>::<span style="color:rgb(161,103,230)">cout</span> <<
<span style="color:rgb(252,106,93)">"LOG2\n"</span>;};</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(108,121,134);background-color:rgb(31,31,36)">
//    void (*f)() = [](){std::cout << "LOG3\n";};</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36);min-height:14px">
    </p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36)">
    f();</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36);min-height:14px">
    </p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36)">
    <span style="color:rgb(252,95,163)"><b>return</b></span> <span style="color:rgb(208,191,105)">
0</span>;</p>
<p style="margin-right:0px;margin-left:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;color:rgba(255,255,255,0.85);background-color:rgb(31,31,36)">
}</p>
<div><br>
</div>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont"><br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">Thanks,</p>
<p style="font-family:Calibri,Helvetica,sans-serif,serif,EmojiFont">Cyril</p>
</div>
<p></p>
<p class="gmail-m_-350041447199119474ImprintUniqueID"></p>
<p></p>
<p class="gmail-m_-350041447199119474ImprintUniqueID">
</p><table class="gmail-m_-350041447199119474ImprintUniqueIDTable" style="width:600px;border-collapse:collapse" cols="2" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="font-size:7pt">
<td style="width:50px;vertical-align:top;padding-top:7px"><img style="border-width: 0px; border-style: solid; border-color: currentcolor; border-image: none;" src="cid:176e20de8aa54e97fc01"></td>
<td style="font-size:7pt;font-family:Verdana;width:219px;color:rgb(39,67,112);padding-top:10px;padding-left:10px" width="270" valign="top">
<font style="font-size:7pt" face="Verdana" color="#cecece"></font><font style="font-size:7pt" face="Verdana" color="#a1a1a1">
<table style="font-size:7pt;font-family:Verdana;color:rgb(160,160,160)" width="250px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><font style="font-family:Verdana;color:rgb(39,67,112);font-weight:bold">Cyril Makloufi</font></td>
</tr>
<tr>
<td><font style="color:rgb(102,102,102)">Développeur</font></td>
</tr>
</tbody>
</table>
</font><font style="font-size:7pt" face="Verdana" color="#a1a1a1"></font>
<table style="font-size:7pt;font-family:Verdana;color:rgb(160,160,160)" width="240px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="55px"><font style="color:rgb(102,102,102)">Email :</font></td>
<td><font style="color:rgb(102,102,102)"><a href="mailto:Cyril.Makloufi@4d.com" title="Click to send email to Cyril Makloufi" target="_blank">Cyril.Makloufi@4d.com</a></font></td>
</tr>
<tr>
<td width="55px"><font style="color:rgb(102,102,102)">Web :</font></td>
<td><font style="color:rgb(102,102,102)"><a href="http://www.4d.com" title="" target="_blank">www.4d.com</a></font></td>
</tr>
</tbody>
</table>
</td>
<td style="width:1px"></td>
<td style="width:293px;padding-bottom:10px;padding-top:10px" valign="top">
<table style="font-family:Verdana;color:rgb(102,102,102);font-size:7pt;border-left:1px solid rgb(39,67,112);padding-left:10px" width="220px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="150px"><font style="font-family:Verdana;color:rgb(39,67,112);font-weight:bold"><font style="font-family:Verdana;color:rgb(206,206,206)"><font style="font-family:Verdana;color:rgb(206,206,206)">4D SAS</font></font></font></td>
</tr>
<tr>
<td><font style="font-family:Verdana;color:rgb(102,102,102);font-weight:normal"><font style="font-family:Verdana;color:rgb(206,206,206)">66 route de Sartrouville<br>
Parc Les Erables - Batiment 4</font></font></td>
</tr>
<tr>
<td><font style="font-family:Verdana;color:rgb(102,102,102)"><font style="font-family:Verdana;color:rgb(206,206,206)">78230<font style="font-family:Verdana;color:rgb(206,206,206)">
</font>Le Pecq<font style="font-family:Verdana;color:rgb(206,206,206)"> - </font>France</font></font></td>
</tr>
</tbody>
</table>
<table style="font-family:Verdana;color:rgb(102,102,102);font-size:7pt;border-left:1px solid rgb(39,67,112);padding-left:10px" width="250px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="53px"><font style="font-family:Verdana;color:rgb(102,102,102);font-weight:normal"><font style="font-family:Verdana;color:rgb(206,206,206)"><font style="font-family:Verdana;color:rgb(206,206,206)">Standard :</font></font></font></td>
<td><font style="font-family:verdana;color:rgb(10,44,42)"><font style="font-family:Verdana;color:rgb(206,206,206)">+33 1 30 53 92 00</font></font></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<font color="#ff6600">
<p class="gmail-m_-350041447199119474ImprintUniqueID" style="font-size:7pt">
</p><table class="gmail-m_-350041447199119474ImprintUniqueIDTable" style="height:86px;width:300px;border-collapse:collapse;padding-left:25px" cols="1" cellspacing="0" cellpadding="0" border="0">
<tbody>
</tbody>
</table>
<p></p>

<p class="gmail-m_-350041447199119474ImprintUniqueID" style="font-size:7pt"><br>
</p>
<p class="gmail-m_-350041447199119474ImprintUniqueID"><font face="Verdana"></font></p>
<p></p>
<p></p>
<p></p>
</font>
<p></p>
<p class="gmail-m_-350041447199119474ImprintUniqueID" align="left"></p>
<p class="gmail-m_-350041447199119474ImprintUniqueID"></p>
<p align="left">  </p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>

_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">You can get very substantial performance improvements<br>by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler<br>So if you're looking for a completely portable, 100% standards-conformant way<br>to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)</div>