views:

41

answers:

1
public class ReplacementService : IReplacementService
{
    public List<int> GetTeamReplacementWeight(int iTeamId)
    {
        IEnumerable<TeamReplacementGroup> groups = TeamReplacementGroup.GetTeamGroups(iTeamId);
        List<int> weights= groups
            .Select(group => group.GetWeight())
            .AsParallel()
            .ToList();

        return weights;
    }
}

'GetWeight' operation is relatively small (for 1 object it could be executed not longer then 1ms).

Does it make sense to use 'AsParallel' if collection size is in range 3-8 elements? I would definitely use it for sequences with more then 100 elements, but for small...

My concern is that expenses for threads creation and waiting for their completion, with following composing results into one array will take more resources then possible benefit of different threads usage.

Do you think that my concern is valuable?

Any thoughts are welcome!

+1  A: 

Your concern does sound valid. You could do some tests/benchmarks to see for sure? Here is a resource from Microsoft.

bluevoodoo1