【发布时间】:2011-01-22 19:23:37
【问题描述】:
public IQueryable<T> GetRecords<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression, int from, int first) where T : class, new()
{
first = first == 0 ? 30 : first;
return _db.GetCollection<T>(collectionName).Linq().Where(expression).Skip(from).Take(first);
}
var x = GetRecords<Event>(p => true, 0, 12222);
string eventJson = new JavaScriptSerializer().Serialize(x);
这个函数从 mongoDB 中获取数据。
SqlDataReader dr = SqlHelper.ExecuteReader("Select Top(12222)* From NewsFeed");
string eventJson = new JavaScriptSerializer().Serialize(dr);
这来自 SQL Server 。
我试图测量它们每个的执行时间,结果是:
Mongo : 172ms
SQL:185毫秒。
但据我所知,mongoDB 应该比 SQL 快太多了,对吧!?!
【问题讨论】:
-
为什么你认为它应该更快?
-
为什么我认为 mongo 应该比 SQL 更快!?!
-
你也应该意识到你的很多开销可能不在数据层,它可能来自数据的迭代和反序列化。并非总是在所有用例中都使用 MongoDB >> SQL。
标签: c# linq performance mongodb