[erlang-questions] byte_size/1 vs variable access
Tue Feb 25 22:56:21 CET 2014
Been wondering something pretty much insignificant recently.
When I need the size of a binary I tend to create a variable, say:
DataSize = byte_size(Data)
and then I reuse this variable in the function.
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.
More information about the erlang-questions