Attributes are wonderful for decorating your Enums with additional markup and meta data. However, looking up attributes via reflection is not always a fast operation in terms of performance. Additionally, no one likes typing that code over and over again.
Well not to worry, just use the following extension methods to help cache your Enum attribute look ups, and increase your application's performance! But how much faster is this? Good question...
Iterations | Average Elapsed Ticks | Difference | |
---|---|---|---|
No Cache | With Cache | ||
2 | 1182.00 | 3934.00 | 4x Slower |
10 | 20.10 | 7.10 | 3x Faster |
100 | 13.07 | 1.37 | 10x Faster |
1,000 | 13.27 | 1.40 | 10x Faster |
10,000 | 13.56 | 1.45 | 10x Faster |
100,000 | 13.02 | 1.33 | 10x Faster |