|
There's a few things I think you need to take into acccunt there. Firstly, if you up the 100 to 100 million, the simple iteration is three times as quick (on my computer). When you time a small loop with 100 items in it, really you're just timing the JIT compilation time, not the actual execution time which will be super sub-millisecond. The LINQ has been pre-jitted as its part of the .NET framework so you'd expect that (the first time). Also, timers aren't that accurate so really I think you need large numbers of iterations to be able to draw comparisons, and when you do that, again, LINQ is several times slower.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks (no really) I'm off to expand my learning, I like it when things like this happen
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Hope I didn't sound argumentative.
Regards,
Rob Philpott.
|
|
|
|
|
Hmm Interesting subject the performance of LinQ and I don't really know or understand it until now, glad I butted in on this thread
Quote: LINQ-to-Objects generally is going to add some marginal overheads (multiple iterators, etc). It still has to do the loops, and has delegate invokes, and will generally have to do some extra dereferencing to get at captured variables etc. In most code this will be virtually undetectable, and more than afforded by the simpler to understand code.
which I read on this LinQ statement faster than foreach loop[^]
But in another article LinQ performance faq[^]. It goes on to say that doing certain operations in LinQ has an impact on memory such as the OrderBy() extension as it creates a new copy of the list / array in memory as well as the original, but you can improve performance by utilizing chaining and Lazy evaluation.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
We did similar tests about a year or two ago and also inlcuded unmanaged C++, which was still several times faster than the simple managed loop.
|
|
|
|
|
Windows is not a "real-time" operating system so I don't know what you expect to get out of the code.
|
|
|
|
|
What no one has mentioned is where the actual issue is here. It's not in the line of code that you probably think it is. As a hint, put a sw.Stop(); just before the line count = x.Count(); . This should show you what the actual hold up is (as a hint - the first part of that statement doesn't actually return a concrete list. As LINQ utilizes lazy evaluation and deferred execution, you effectively end up with the actual iteration being done twice (the second time in the Count() method).
|
|
|
|
|
Yep, I appreciate that which is why the way the code is (timer after count). Just another wonderful aspect of LINQ. I don't see why the iteration is being done twice though. The query sets up an enumerator and the count enumerates it. Where are the two iterations? And most importantly, can you suggest a change which will make the LINQ execution speed similar (presumably get it down to just one iteration)?
EDIT: corrected some of the jargon, got two kids running around the place and so first part was rushed and incoherent.
Regards,
Rob Philpott.
modified 30-Apr-13 13:04pm.
|
|
|
|
|
Its been a fun bit of learning, but I have worked out why it is significantly slower.
The Count() method uses eager evaluation, from reading various sources, this means that the collection is iterated in full when in this case count() is called.
so
var x = from g in numbers where g % 7 == 0 select g;
count = x.Count();
This block uses lazy evaluation to create x, but it is not evaluated until you call Count() which uses eager evaluation.
and
int Count = numbers.Count(p => p % 7 ==0);
this block causes the entire 10 million records to be evaluated.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Strange - I'm not seeing the same results, and my computer isn't exactly new. Running in LinqPad, I get:
- Release mode:
- Simple Iteration : 2107
- LINQ Query : 2168
- Count Query : 2255
- Debug mode:
- Simple Iteration : 2273
- LINQ Query : 2281
- Count Query : 2758
Yes, there's a small difference, but at worst it's less than a 20% hit. It's certainly not taking three times as long.
If you add PLINQ into the picture, your loop starts to look pretty slow:
count = numbers.AsParallel().Count(g => g % 7 == 0);
- Simple Iteration : 2218
- PLINQ Query : 1749
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes! I was missing something - I hadn't tried it in release. What an idiot.
I get about the same as you with that change, it drops from 100% longer to about 20% which is a lot more palatable. And like you, if I make it parallel its actually quicker.
This requires a recalibration of my attitude to LINQ. 20% still makes me feel uncomfortable but is much better than I thought.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: half the performance is a serious issue in a real-time system
By most definitions Windows is not a real time OS so of course C# isn't suitable for a real time system.
Regardless of what syntax you use.
Rob Philpott wrote: Because, unless I'm missing something
I design and write high performance systems and have been doing so for more than a decade and micro-optimizations have no impact on normal high performance business systems. Matter of fact neither does language (and I am very experienced in C#, Java and C++ and have experience in others.)
If you want to profile an application, versus a code snippet then you might want to buy a profiler tool and learn how to use it.
|
|
|
|
|
string GetDefaultPrinter()
{
PrinterSettings settings = new PrinterSettings();
foreach (string printer in PrinterSettings.InstalledPrinters)
{
settings.PrinterName = printer;
if (settings.IsDefaultPrinter)
return printer;
}
return string.Empty;
}
ShowReport()
{
ReportDocument rptdoc = new ReportDocument();
info = clsConnection.GetConnectionInfo();
path = "reports/AccessoryPurchaseOrder.rpt";
rptdoc.Load(Server.MapPath(path));
clsConnection.ConfigureLogonInfo(rptdoc, info);
pfItemYr.ParameterFieldName = "@transid";
dcItemtransid.Value = transid;
pfItemYr.CurrentValues.Add(dcItemtransid);
paramFields.Add(pfItemYr);
rptdoc.SetParameterValue("@transid", transid);
rptdoc.SetParameterValue("userid", userid);
rptdoc.SetParameterValue("systemid", sysid);
rptdoc.Load(Server.MapPath(path));
try
{
rptdoc.PrintOptions.PrinterName = GetDefaultPrinter();
rptdoc.PrintToPrinter(1, true, 0, 0);
rptdoc.Close();
rptdoc.Dispose();
Label1.Text = Label1.Text +GetDefaultPrinter();
}
catch (Exception ex)
{
PreviewViewer.ReportSource = rptdoc;
}
}
|
|
|
|
|
Don't swallow the exception, but log it or display it. If something goes wrong, that's the thing that'll tell you WHAT went wrong.
Without that information, "going wrong" could mean anything.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am getting "No Printers are Installed" error message(Only in published file).
|
|
|
|
|
CR "needs" to have a printer installed. Such a report is based on a print-preview. Now, I don't think that you want to buy one, just to run some reports.
A PdfPrinter[^] (or similar) would "fake" a printer, and if you were to print on it, it'd generate a PDF file. You needn't use the tool, just install it - that way CR has a printer and will stop complaining, even if it's just a "fake" printer.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have an IE toolbar with a button that runs a bat script with Process.Start. I tried also with a PS script.
When I open IE, the button works. As soon as I navigate to another address or open a new tab, it fails running the script.
I think it has to do with the toolbar restarting each time I navigate to a new address or open a new tab.
private void assign_Click(object sender, EventArgs e)
{
Process.Start("c:\\users\\ccormeni\\Documents\\scripts\\openoneinc.bat");
}
Any help appreciated.
Clovis
|
|
|
|
|
<asp:linkbutton id="Lbtn" runat="server" text="click here">
<asp:panel id="Panel1" runat="server" style="display: none; padding: 10px; border: 1px;
border-style: solid;" backcolor="#FF9933" width="400px" visible="true">
username:
| <asp:textbox id="TextBox1" runat="server">
| Password: | <asp:textbox id="TextBox2" runat="server">
|
<asp:button id="Button1" runat="server" text="submit" onclick="Button1_Click">
<cc1:modalpopupextender id="ModalPopupExtender" runat="server" targetcontrolid="Lbtn"
="" popupcontrolid="Panel1" backgroundcssclass="backgroundColor" dropshadow="true" popupdraghandlecontrolid="header">
<asp:panel id="Panel2" runat="server" style="display: none; padding: 10px; border: 1px;
border-style: solid;" backcolor="#FF9933" width="400px" visible="false">
<asp:label id="Label1" runat="server">
<cc1:modalpopupextender id="ModalPopupExtender1" runat="server" targetcontrolid="Button1"
="" popupcontrolid="Panel2" backgroundcssclass="backgroundColor" dropshadow="true" popupdraghandlecontrolid="header">
the problem is am not getting my second popup displayed when the submit button of login page in the popup is clicked
sneha
|
|
|
|
|
Have a look at the definition of a modal form:
What is a modal form?[^]
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
In WinForms, one can show a modal form from within a modal form. How is your link being helpful?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: In WinForms, one can show a modal form from within a modal form. How is your link being helpful?
He is not using winforms...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
That doesn't change much; whether or not he's using winforms doesn't change the concept.
If it's a limitation of ASP, I'd expect somewhat more explanation than a link to "Let me Google that for you".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
LMGTFYTPTCBFY
Let me google that for you then paste the contents below for you
modal form
Web definitions
when a modal form displayed, no other form in the application can receive the focus until the modal form is closed; no other statements...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Thanks for the copy/paste. Says the same as the WinForm-version, and does not imply that the modal form itself cannot launch anything. The text that no other statements are executed is an oversimplification; the modal form still has to process paint-operations.
I can imagine "why" it wouldn't work in a webform, but this isn't a valid enough reason.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am unable to test it but I thought it was a clue
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|