|
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
|
|
|
|
|
lordoftrades wrote: I writing this code in the software of IQBroker. I think you will get better help at http://www.iqbroker.com/[^].
Use the best guess
|
|
|
|
|
lordoftrades wrote: 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. Create some mock-objects to fake the IBroker-objects and write the logic in a real IDE
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You wrote, that in VBA you would use a loop. However in this code I see no loop at all. Maybe the entry and exit conditions are mutually exclusive and don't appear on the same day?
|
|
|
|
|
I'm just pointing out a minor typo in // When to exit
yyesterdayshighest13Value
|
|
|
|
|