I want to implement two methods: AddPlayers and AddPlayer. Is it better when AddPlayers calls AddPlayer or AddPlayer calls AddPlayers with a single item array? Is there a significant difference in performance and IL output?
// AddPlayers contains the logic
void AddPlayer(Player player)
{
return AddPlayers(new [] { player });
}
vs
// AddPlayer contains the logic
void AddPlayers(IEnumerable<Player> players)
{
foreach (var player in players)
{
AddPlayer(player);
}
}
AddPlayerneeds some noteable time, because it produces some database insert. If it just adds an object in-memory to a list, there may be no measurable performance difference, however. So you should always measure, at least make a rough estimation. – Doc Brown Dec 06 '18 at 16:46