-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed as not planned
Labels
Description
Hello, i did some performance testing and would propose changes to DateTime.DaysInMonth(int year, int month)
private static ReadOnlySpan<byte> DaysInMonth365 => new byte[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
DaysInMonth365[month - 1];
Change to:
private static readonly byte[] DaysInMonth365 = new byte[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
DaysInMonth365[month];
As the array is used as a lookup i would remove the -1
Operation, also i think DaysInMonth365
should be a field instead of a property.
I've noticed 5x Performance gains by doing lookups in a byte[] field instead of creating a new ReadOnlySpan every time through a property.