Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Insider News
  4. Performance benefits of sealed class in .NET

Performance benefits of sealed class in .NET

Scheduled Pinned Locked Moved The Insider News
csharpoopperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kent Sharkey
    wrote on last edited by
    #1

    Meziantou[^]:

    A new analyzer should be available in .NET 7 to detect classes that can be sealed. In this post, I'll show some performance benefits of sealed classes.

    "Signed, sealed, delivered, I'm yours"

    But don't put it in your will, as there's no inheritance!

    D 1 Reply Last reply
    0
    • K Kent Sharkey

      Meziantou[^]:

      A new analyzer should be available in .NET 7 to detect classes that can be sealed. In this post, I'll show some performance benefits of sealed classes.

      "Signed, sealed, delivered, I'm yours"

      But don't put it in your will, as there's no inheritance!

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      Either some of those benchmarks aren't being reported correctly, or the compiler has optimized the inner loop into a no-op.

      Quote:

      Method Mean Error StdDev Ratio Code Size
      NonSealed 0.0668 ns 0.0156 ns 0.0138 ns 1.00 64 B
      Sealed 0.0307 ns 0.0209 ns 0.0185 ns 0.50 35 B

      A duration of 0.0307ns corresponds to 1 clock cycle on a 32.5ghz chip. :doh: Even competitive overclockers using liquid nitrogen cooling can't get that fast.

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups