c# XML和SQL哪个更快?

时间:2021-12-15 02:58:36

Which is faster in C#:to read tiny XML files or to read tiny SQL tables with small amount of data ?

在c#中,读小XML文件或读小数据的小SQL表哪个更快?

I wonder if is really necessary to create a table in SQL then establish a connection just to read 10 or 11 parameters.

我想知道是否真的需要在SQL中创建一个表,然后建立一个连接来读取10或11个参数。

What would you reccomend?

你推荐什么?

5 个解决方案

#1


1  

It's really depends on what You need. Nothing stops You from even combining the two worlds as XML can easily be stored in SQL Server.

这取决于你需要什么。没有什么能阻止您将这两个世界组合在一起,因为XML可以轻松地存储在SQL Server中。

If You want to actually have the authentication of the SQL Server, have it backed up, versioned or whatever, You can easily design a mixed XML, SQL, table solution. If You really need some propertyBag persistence area files are ok, but they still require care ie. access control, taking care when it is not present etc (reading a file still does throw a lot of exceptions and IT does it with some good reason).

如果您希望实际拥有SQL Server的身份验证,那么您可以轻松地设计一个混合的XML、SQL、表解决方案。如果您确实需要一些propertyBag持久性区域文件是可以的,但是它们仍然需要小心。访问控制,当它不存在时要小心等等(读取一个文件仍然会抛出很多异常,并且它这样做是有原因的)。

Ask Yourself questions like: do I need restricted access, how will I report changes (if any),

问自己这样的问题:我是否需要受限访问,我将如何报告更改(如果有的话),

  • do I need version history,
  • 我是否需要版本历史,
  • do I read all the parameters or only part of it?
  • 我是读所有的参数还是只读一部分?
  • what Do i need to do if someone changes an entry?
  • 如果有人更改条目,我需要做什么?
  • what should I do when there is no entry?
  • 如果没有入口,我该怎么办?
  • does it need to be extensible (new parameters added/removed)?
  • 是否需要可扩展(添加/删除新参数)?
  • should it be encrypted?
  • 它应该加密吗?
  • does the database layer needs to know about it?
  • 数据库层需要知道它吗?

Just some thought from the top of my head. Luke

从我的头顶就能想到。路加福音

#2


1  

If you just have a handful of 'settings' that you want to read, I would definitely go with a small XML file. I can't say definitively that it would be faster, but given that you would eliminate the over head of establishing the connection, authenticating, etc it would definitely be simpler.

如果您只想要阅读一些“设置”,我肯定会使用一个小XML文件。我不能肯定地说它会更快,但是考虑到您将消除建立连接、验证等方面的开销,它肯定会更简单。

And if you can use LINQ to XML, its really easy to do.

如果您可以使用LINQ到XML,这真的很容易做到。

#3


1  

Speed is not the only consideration. You don't have as much admin overhead with XML files as you would with SQL Server.

速度不是唯一的考虑因素。XML文件的管理开销没有SQL Server那么大。

If the file is local, it will certainly be faster to read using direct file than networked SQL access. Far less between you and the data. No impact on your process from other SQL usage.

如果文件是本地的,那么使用直接文件进行读取肯定比使用网络SQL访问要快。你和数据之间的距离要小得多。其他SQL使用对进程没有影响。

#4


1  

reading a lot of files is slow so if you have tons of xml files i would vote for SQL especially if we consider the fact that you have to parse the xml files as well which is way more complicated and more time consuming then making a connection to a DB especially if the DB is on the localhost :)

阅读大量的文件很慢所以如果你有吨的xml文件我会投票给SQL尤其是如果我们考虑一个事实,那就是你必须解析xml文件以及更复杂和更费时然后做一个连接到数据库特别是DB在localhost:)

#5


0  

SQL based method: pros Easy to migrate, configure SQL based method: cons Connection can be down, connection takes time to establish, DB admin will wonder why there is a tiny table that has no meaning, codebase become unnecessarily complex File based method: pros Fast, no overhead on DB File based method:cons Migration is an issue. Configuration is an issue. Can easily get corrupted.

基于SQL的方法:优点容易迁移,配置基于SQL的方法:缺点连接可以下来,需要时间来建立连接,数据库管理员想知道为什么会有一个小桌子,没有意义,代码变得不必要的复杂基于文件的方法:优点快,没有开销DB基于文件的方法:缺点迁移是一个问题。配置是一个问题。很容易损坏。

#1


1  

It's really depends on what You need. Nothing stops You from even combining the two worlds as XML can easily be stored in SQL Server.

这取决于你需要什么。没有什么能阻止您将这两个世界组合在一起,因为XML可以轻松地存储在SQL Server中。

If You want to actually have the authentication of the SQL Server, have it backed up, versioned or whatever, You can easily design a mixed XML, SQL, table solution. If You really need some propertyBag persistence area files are ok, but they still require care ie. access control, taking care when it is not present etc (reading a file still does throw a lot of exceptions and IT does it with some good reason).

如果您希望实际拥有SQL Server的身份验证,那么您可以轻松地设计一个混合的XML、SQL、表解决方案。如果您确实需要一些propertyBag持久性区域文件是可以的,但是它们仍然需要小心。访问控制,当它不存在时要小心等等(读取一个文件仍然会抛出很多异常,并且它这样做是有原因的)。

Ask Yourself questions like: do I need restricted access, how will I report changes (if any),

问自己这样的问题:我是否需要受限访问,我将如何报告更改(如果有的话),

  • do I need version history,
  • 我是否需要版本历史,
  • do I read all the parameters or only part of it?
  • 我是读所有的参数还是只读一部分?
  • what Do i need to do if someone changes an entry?
  • 如果有人更改条目,我需要做什么?
  • what should I do when there is no entry?
  • 如果没有入口,我该怎么办?
  • does it need to be extensible (new parameters added/removed)?
  • 是否需要可扩展(添加/删除新参数)?
  • should it be encrypted?
  • 它应该加密吗?
  • does the database layer needs to know about it?
  • 数据库层需要知道它吗?

Just some thought from the top of my head. Luke

从我的头顶就能想到。路加福音

#2


1  

If you just have a handful of 'settings' that you want to read, I would definitely go with a small XML file. I can't say definitively that it would be faster, but given that you would eliminate the over head of establishing the connection, authenticating, etc it would definitely be simpler.

如果您只想要阅读一些“设置”,我肯定会使用一个小XML文件。我不能肯定地说它会更快,但是考虑到您将消除建立连接、验证等方面的开销,它肯定会更简单。

And if you can use LINQ to XML, its really easy to do.

如果您可以使用LINQ到XML,这真的很容易做到。

#3


1  

Speed is not the only consideration. You don't have as much admin overhead with XML files as you would with SQL Server.

速度不是唯一的考虑因素。XML文件的管理开销没有SQL Server那么大。

If the file is local, it will certainly be faster to read using direct file than networked SQL access. Far less between you and the data. No impact on your process from other SQL usage.

如果文件是本地的,那么使用直接文件进行读取肯定比使用网络SQL访问要快。你和数据之间的距离要小得多。其他SQL使用对进程没有影响。

#4


1  

reading a lot of files is slow so if you have tons of xml files i would vote for SQL especially if we consider the fact that you have to parse the xml files as well which is way more complicated and more time consuming then making a connection to a DB especially if the DB is on the localhost :)

阅读大量的文件很慢所以如果你有吨的xml文件我会投票给SQL尤其是如果我们考虑一个事实,那就是你必须解析xml文件以及更复杂和更费时然后做一个连接到数据库特别是DB在localhost:)

#5


0  

SQL based method: pros Easy to migrate, configure SQL based method: cons Connection can be down, connection takes time to establish, DB admin will wonder why there is a tiny table that has no meaning, codebase become unnecessarily complex File based method: pros Fast, no overhead on DB File based method:cons Migration is an issue. Configuration is an issue. Can easily get corrupted.

基于SQL的方法:优点容易迁移,配置基于SQL的方法:缺点连接可以下来,需要时间来建立连接,数据库管理员想知道为什么会有一个小桌子,没有意义,代码变得不必要的复杂基于文件的方法:优点快,没有开销DB基于文件的方法:缺点迁移是一个问题。配置是一个问题。很容易损坏。