Material layer VS material function

I am reading the documentation available on UE4 and seeing videos on youtube, but I do not understand when choose a function or a layer. In the image below, I show you that using both the methods I get the same result.

May you help me to understand when is better to use the layer and the function, and which is the less expencive for CPU and GPU? Thank you for your time.