|
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
|
|
|
|
|
I'm creating .avi files (using VFW), the files consist of screen capture images displayed at 1 fps. I found some sample code for c# at:
http://www.adp-gmbh.ch/csharp/avi/write_avi.html[]
This creates the ,avi file with my images in. However I'm getting a variable number of blank frame at the beginning of the file. Sometimes over 50 blank frames (a lot at 1 fps!). There appears to be no consistency to the number of blank frames, different codecs or recording lengths have no consistent effect on their number.
Some media players when playing the avi's just show the first correct frame a number of times, virtual dub initially shows them as blank and subsequently as distorted images.
Does anyone have any idea what I may be doing wrong?
James
|
|
|
|
|
Hello
I'm trying to create a program that scan the values and compare values against some average highest or loweste values. It seems to me that the entry is no problem, but getting out of the position is not working as it should.
I'm used to VBA, and there I'd just set up a loop to start IF an entrysignal was trigged. And that loop would run until exitsignal was trigged...
But I'm not experienced at all with writing in C#, so I'm not sure how this code actually runs, ie step-by-step:
if (Value < yesterdayslowest50Value && yyesterdayslowest50Value > yesterdaysValue) {
if (_enableShorting && PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, 0, IQ_TIF.DAY, "CoverToLong");
}
if (!PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
int orderIndex = BrokerMarket(IQ_ActionType.BUY, symbolIndex, 0, IQ_TIF.DAY, "Long");
BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
}
if(Value > yesterdayshighest13Value && yesterdaysValue < yyesterdayshighest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
{
int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
double quantity = PositionQuantity(positionIndexes[0]);
BrokerMarket(IQ_ActionType.SELL, symbolIndex, quantity, IQ_TIF.DAY, "Sell");
}
}
else if (Value > yesterdayslowest13Value && yyesterdayslowest13Value < yesterdaysValue) {
if (PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
BrokerMarket(IQ_ActionType.SELL, symbolIndex, 0, IQ_TIF.DAY, "SellToShort");
}
if (_enableShorting && !PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
int orderIndex = BrokerMarket(IQ_ActionType.SELL_SHORT, symbolIndex, 0, IQ_TIF.DAY, "Short");
BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
}
if(Value < yesterdayslowest13Value && yesterdaysValue > yyesterdayslowest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
{
int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
double quantity = PositionQuantity(positionIndexes[0]);
BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, quantity, IQ_TIF.DAY, "Cover");
}
}
It seems that my code have issues exiting the trades. BTW I've used IQBrokers software to program this.
If anyone see some obviouse mistake I'd appreciate it.
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: so I'm not sure how this code actually runs, ie step-by-step:
Press F10 instead of F5.
Press F10 again.
Press F10 again.
Press F10 again.
That's how it get's executed, statement by statement. Hover the mouse over a variable to see it's contents.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello
That would have worked fine in VisualStudio, but I writing this code in the software of IQBroker. There are no such step-by-step features as I can see. And I think it will be pretty big mess if I try to open the code in VS, as I'm not sure how to get control over all subcodes and the database too.
Kind regards
Espen
|
|
|
|
|