Welcome to the Lounge
The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
Probably there, you get an int instead of a decimal?
Fueled By Caffeine wrote:var processedPerSecond = processedCount / elapsedTime * 1000;
decimal will still result in a wrong output as an
int is silently cast to a
decimal, but that doesn't change outcome of the divide operation.
The fix I think you're looking for is:
var processedPerSecond = (decimal)processedCount / elapsedTime * 1000;Now here is a fun bug, which I've seen go wrong multiple times...
var query = databaseContext.SomeTable;
query = query.Where(x => x.SomeBoolLimitingTheResultFromThousandsToTens);
return query.ToList();In this piece of code the
query variable is of type
That means the
Where that is executed is actually
The actual database call, with
WHERE clause, is executed on the
ToList method (or more precise, in the
Now someone comes and changes the code, the first line becomes
var query = databaseContext.SomeTable.ToList();
Suddenly, the type of
query has changed to
The database query WITHOUT the
WHERE clause is executed and
Enumerable.Where(IEnumerable, Func) is executed to filter the collection in-memory.
You now get thousands of records instead of tens, while the in-memory
Where is probably more expensive than the database
All in all a nice performance hit...
That is actually the only bug I've ever encountered while working with
var, and it's pretty specific.
And the only reason it goes wrong is because
IEnumerable have pretty much the same extension methods, save for
Func, but a
Func can be implicitly cast to an
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.