How fast is linq?

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am getting some statistics about my database to display on the web
site. For example:

IQueryable<Article> articles = GetArticles();
ArticlesStat stat = new ArticlesStat {
Count = articles.Count(),
CountPerMonth = Math.Round(articles.Count() / (Double)
(DateTimeHelpers.Count(articles.Min(a => a.Created), DateTime.UtcNow,
DateInterval.Month).GetValueOrDefault(1) == 0 ? 1 :
DateTimeHelpers.Count(articles.Min(a => a.Created), DateTime.UtcNow,
DateInterval.Month).GetValueOrDefault(1)), 1),
PublishedCount = articles.Where(a => a.Published == true).Count(),
PublishedShare = Math.Round(articles.Where(a => a.Published ==
true).Count() / (Double)(articles.Count() == 0 ? 1 : articles.Count())
* 100, 1),
}

I have a few more statistics.

My question is should I just get the statistics I need or if I get all
(4 times more similar properties that what I am posting) will I get a
much delayed execution?

The quote is not so complex. I get, as you can see the articles:
IQueryable<Article> articles = GetArticles();

And then I define an object with some calculation.

Thanks,
Miguel
 
1000000 times or more quicker then your Internet connection.

Focusing on this part of your solution is the worst place to put any effort
in.

Something is always as quick as the smallest gap and that is for sure not
Linq in your web solution.

Not much different from what Peter wrote, however, seen from another point
of view.

jmo

Cor
 
I do not understand your reasoning. If the user experience is too be slowed
down already by the Internet connection why make the user wait more because
you use an inferior technology.

DataReaders are by far the fastest way to populate model objects and by some
distance.

The results here are actually shocking, especially considering he is
measuring against compiled Linq queries.

http://www.devtoolshed.com/node/12

Finally the effort to create a proper DataReader based DAL is overestimated
by many people advocating Linq on here.
 
Paul said:
I do not understand your reasoning. If the user experience is too be slowed
down already by the Internet connection why make the user wait more because
you use an inferior technology.

DataReaders are by far the fastest way to populate model objects and by some
distance.

The results here are actually shocking, especially considering he is
measuring against compiled Linq queries.

http://www.devtoolshed.com/node/12

Finally the effort to create a proper DataReader based DAL is overestimated
by many people advocating Linq on here.

You want speed in accessing entities on the model then one uses
Entity-SQL (ESQL), which is not unlike using T-SQL, ADO.NET SQL Command
Objects and a datareader, and its database reader that is part of the
ADO.Net Framework.
 
Of course, in this particular question, the other issue is "how often will  
you actually be doing this?"  If the statistics are things that would be  
useful, and they are retrieved on-demand only, rather than being part of  
some repetitive, complex processing, then even if it is slow, maybe that  
doesn't matter so much.

I am not sure yet. But my first intention is to display about 3
statistic values from a list of possible 12 in some pages of the web
site, for example, on the articles or documents page ... or on the
home page with a global overview.

So on each page I am getting the page content from the SQL database
and a few stats.
 
Back
Top