Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

To take Jesse C. Slicer's answer a bit further.. I cleaned up the code to use constants and string.Format... It makes more sense from an architectural stand point. Sealing the class is also a performance boost for JIT, but the benefit should be minimal at best. As stated in this other stack overflow post, it's more of a late result type of performance enhancement. You more than likely won't see anything from it.

internal sealed class Program
 {
 private const string READY = "READY";
 private const string NOT_READY = "NOTREADY";
 private const string DRIVE = "DRIVE";
 private static void Main(string[] args)
 {
 var driveInfoDictionary = DriveInfo.GetDrives().ToDictionary(d => d.Name);
 foreach (var drive in args
 .Select(arg => arg.ToUpperInvariant().Split('-'))
 .Where(parts => (parts.Length == 2) && parts[0].Equals(DRIVE) && driveInfoDictionary.ContainsKey(string.Format("{0}:\\", parts[1])))
 .Select(parts => driveInfoDictionary[string.Format("{0}:\\", parts[1])]))
 Console.WriteLine("{0},{1},{2}",
 (drive.IsReady ? drive.TotalSize : 0L),
 (drive.IsReady ? drive.TotalFreeSpace : 0L),
 (drive.IsReady ? READY : NOT_READY));
 }
 }

http://stackoverflow.com/questions/2134/do-sealed-classes-really-offer-performance-benefits https://stackoverflow.com/questions/2134/do-sealed-classes-really-offer-performance-benefits

To take Jesse C. Slicer's answer a bit further.. I cleaned up the code to use constants and string.Format... It makes more sense from an architectural stand point. Sealing the class is also a performance boost for JIT, but the benefit should be minimal at best. As stated in this other stack overflow post, it's more of a late result type of performance enhancement. You more than likely won't see anything from it.

internal sealed class Program
 {
 private const string READY = "READY";
 private const string NOT_READY = "NOTREADY";
 private const string DRIVE = "DRIVE";
 private static void Main(string[] args)
 {
 var driveInfoDictionary = DriveInfo.GetDrives().ToDictionary(d => d.Name);
 foreach (var drive in args
 .Select(arg => arg.ToUpperInvariant().Split('-'))
 .Where(parts => (parts.Length == 2) && parts[0].Equals(DRIVE) && driveInfoDictionary.ContainsKey(string.Format("{0}:\\", parts[1])))
 .Select(parts => driveInfoDictionary[string.Format("{0}:\\", parts[1])]))
 Console.WriteLine("{0},{1},{2}",
 (drive.IsReady ? drive.TotalSize : 0L),
 (drive.IsReady ? drive.TotalFreeSpace : 0L),
 (drive.IsReady ? READY : NOT_READY));
 }
 }

http://stackoverflow.com/questions/2134/do-sealed-classes-really-offer-performance-benefits

To take Jesse C. Slicer's answer a bit further.. I cleaned up the code to use constants and string.Format... It makes more sense from an architectural stand point. Sealing the class is also a performance boost for JIT, but the benefit should be minimal at best. As stated in this other stack overflow post, it's more of a late result type of performance enhancement. You more than likely won't see anything from it.

internal sealed class Program
 {
 private const string READY = "READY";
 private const string NOT_READY = "NOTREADY";
 private const string DRIVE = "DRIVE";
 private static void Main(string[] args)
 {
 var driveInfoDictionary = DriveInfo.GetDrives().ToDictionary(d => d.Name);
 foreach (var drive in args
 .Select(arg => arg.ToUpperInvariant().Split('-'))
 .Where(parts => (parts.Length == 2) && parts[0].Equals(DRIVE) && driveInfoDictionary.ContainsKey(string.Format("{0}:\\", parts[1])))
 .Select(parts => driveInfoDictionary[string.Format("{0}:\\", parts[1])]))
 Console.WriteLine("{0},{1},{2}",
 (drive.IsReady ? drive.TotalSize : 0L),
 (drive.IsReady ? drive.TotalFreeSpace : 0L),
 (drive.IsReady ? READY : NOT_READY));
 }
 }

https://stackoverflow.com/questions/2134/do-sealed-classes-really-offer-performance-benefits

Source Link
Alex
  • 193
  • 4

To take Jesse C. Slicer's answer a bit further.. I cleaned up the code to use constants and string.Format... It makes more sense from an architectural stand point. Sealing the class is also a performance boost for JIT, but the benefit should be minimal at best. As stated in this other stack overflow post, it's more of a late result type of performance enhancement. You more than likely won't see anything from it.

internal sealed class Program
 {
 private const string READY = "READY";
 private const string NOT_READY = "NOTREADY";
 private const string DRIVE = "DRIVE";
 private static void Main(string[] args)
 {
 var driveInfoDictionary = DriveInfo.GetDrives().ToDictionary(d => d.Name);
 foreach (var drive in args
 .Select(arg => arg.ToUpperInvariant().Split('-'))
 .Where(parts => (parts.Length == 2) && parts[0].Equals(DRIVE) && driveInfoDictionary.ContainsKey(string.Format("{0}:\\", parts[1])))
 .Select(parts => driveInfoDictionary[string.Format("{0}:\\", parts[1])]))
 Console.WriteLine("{0},{1},{2}",
 (drive.IsReady ? drive.TotalSize : 0L),
 (drive.IsReady ? drive.TotalFreeSpace : 0L),
 (drive.IsReady ? READY : NOT_READY));
 }
 }

http://stackoverflow.com/questions/2134/do-sealed-classes-really-offer-performance-benefits

lang-cs

AltStyle によって変換されたページ (->オリジナル) /