这种计数方法在一个单元测试中非常慢。可以通过并行化来改进它吗?
编辑:要清楚,我无法更改日历界面或实现。我对计数算法感兴趣。
public static int CountBusinessDays(ICalendar calendar, DateTime start, DateTime end)
{
int nBusinessDays = 0;
for (DateTime current = start; current <= end; current = current.AddDays(1))
{
if (calendar.IsBusinessDay(current))
++nBusinessDays;
}
return nBusinessDays;
}
public interface ICalendar
{
bool IsBusinessDay(DateTime day);
}