This question is specific to Erlang, but may have general implications to other IO libraries. In Erlang, I can write io:format(IOF, "data: ~p", [Data]) and it will print the contents of the variable Data to the file IOF points to. My question is this: is it better, efficiency-wise, to prefer many small io:format() calls, or one huge one? For example, what would be faster? For purposes of demonstration, assume the size of my Data variables is 1KB each in size, and N > 100,000
Scenario A:
io:format(IOF, "data1: ~p", [Data1])
io:format(IOF, "data2: ~p", [Data2])
...
io:format(IOF, "dataN: ~p", [DataN])
Scenario B:
io:format(IOF, "data1: ~p data2: ~p ... dataN: ~p", [Data1, Data2, ..., DataN])
If this difference is negligible I’m not really interested, but if there could be a large difference then I’m interested in knowing why.
I’d recommend you to research on
file:open/2modes, one of which is{delayed_write, Size, Delay}. It allows you to buffer data and effectively write it to the device.This way either calls wouldn’t probably make a huge difference.