[erlang-questions] byte_size/1 vs variable access

Björn Gustavsson bjorn@REDACTED
Wed Feb 26 12:46:49 CET 2014


On Tue, Feb 25, 2014 at 10:56 PM, Loïc Hoguin <essen@REDACTED> wrote:

> 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?
>
> If someone could shed some light on this perhaps I could stop creating
> variables like this and simplify my code a little more.
>

There is definitely more overhead calling a BIF than accessing a variable.

That said, I doubt that you will be able to notice the difference in a
real program.
So I suggest that you write in the way that you find most readable.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list