<div dir="ltr">I don't know about performance implications, but I've found that it's often necessary to work around limitations of bit matching syntax. Here's an example:<div><br><div><div>1> Foo = <<"asdf">>, FooSize = byte_size(Foo).</div>
<div>4</div><div>2> <<Foo:(byte_size(Foo))/binary, Rest/binary>> = <<"asdfghi">>.</div><div>* 1: illegal bit size</div><div>3> <<Foo:FooSize/binary, Rest/binary>> = <<"asdfghi">>.  <br>
</div><div><<"asdfghi">></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 25, 2014 at 1:56 PM, Loïc Hoguin <span dir="ltr"><<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
Been wondering something pretty much insignificant recently.<br>
<br>
When I need the size of a binary I tend to create a variable, say:<br>
<br>
DataSize = byte_size(Data)<br>
<br>
and then I reuse this variable in the function.<br>
<br>
But considering byte_size/1 is O(1) I am wondering if perhaps that's a little pointless. Is it even worth creating a variable for this? Is perhaps the variable optimized out? Perhaps accessing a variable contents and calling byte_size/1 are equivalent operations? Or the GC that will follow is not worth what little is saved by creating a variable in the first place?<br>

<br>
If someone could shed some light on this perhaps I could stop creating variables like this and simplify my code a little more.<br>
<br>
Thank you.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Loïc Hoguin<br>
<a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</font></span></blockquote></div><br></div>