views:

32

answers:

2

I'm wondering how long it takes (in milliseconds) to read a registry value from the Windows registry through standard C# libraries. In this case, I'm reading in some proxy settings.

What order of magnitude value should I expect? Are there any good benchmark data available?

I'm running WS2k8 R2 amd64. Bonus points: How impactful is the OS sku/version on this measure?

 using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software/Copium")) 
 { 
      return (string)registryKey.GetValue("BinDir"); 
 } 
+1  A: 

Try this link, it is a pretty helpful blog: http://blogs.msdn.com/b/oldnewthing/archive/2006/02/22/536920.aspx

I would add that in general, it is not recommended to store settings in the registry for C# apps, use persisted storage, or a config file or something of that nature. There are problems related to permissions when you deal with the registry. Reading is often not an issue, but if you are going to persist things then it gets hairy, especially with UAC and newer OSs that shadow copy things.

pstrjds
some of the system I am developing apps are locked down to the point where hitting the registry is basically forbidden. Application Data folder is preferred for user data settings, anything else would have to be stored elsewhere.
confusedGeek
as i said, it is to retrieve OS proxy settings. this is not a design choice.
Kenn
A: 

I cannot quote numbers as I don't know. But having just read 30 pages in the Windows Internals 5 book about the registry the following noteworthy things that I didn't know became clear.

  • The Registry is transactional and has fail safes to prevent from being corrupted. This can affect performance. Since the transactional level is read committed, reads shouldn't be blocked by writes so they should be performant.

  • The registry is cached in memory (well frequently used values anyway) so if you access a set of keys often the performance should remain stable after the first hit.

Preet Sangha