|
Gerry Schmitz wrote: The process of "handling an exception" is "expensive" (compute-wise). No, it is not.
Give it a try in a console-app without the debugger attached.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Ok, yours are cheap; the ones I encounter (in my non-console apps), tend to be expensive.
My bad for generalizing.
|
|
|
|
|
Unless a debugger is attached, throwing an exception is not an "expensive" instruction.
Gerry Schmitz wrote: in my non-console apps Use the exact same infrastructure, and the same applies.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In my world (kiosks), anything approaching 100ms is "expensive".
|
|
|
|
|
Expensive compared to which other technique?
Checking if your primary key-field is in the database before doing the insert? Checking if you still have all write permission before doing an update?
--edit
If handling one took 100ms, you'd only be able to throw and handle 10. You can throw (and handle) some thousand exceptions in a second.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 18-Sep-16 8:03am.
|
|
|
|
|
"Expensive" in terms of response time for the user.
(Felt it necessary to add some "data base" nonsense?)
A "thousand exceptions per second" and no impact?
That one is easy to prove.
Just try a couple of combinations of .Parse (with / without exception handling; with and without a valid string). No debugger.
Must be an "anomaly"; Or doesn't that fit your "pattern"?
|
|
|
|
|
Gerry Schmitz wrote: "Expensive" in terms of response time for the user. Expensive is in terms of CPU cost.
Gerry Schmitz wrote: (Felt it necessary to add some "data base" nonsense?) No, just pointing out that catching the exception is usually less expensive than doing a check. Same pattern applies to files, connections etc
Gerry Schmitz wrote: Just try a couple of combinations of .Parse (with / without exception handling; with and without a valid string). No debugger. Yes, parsing is expensive. Throwing exceptions is not.
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
No idea what that means, but here[^] you can copy/paste and see for yourself
50k exceptions in a second. Your definition of "expensive" may vary from mine, ofc.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Exception is Expensive I agree.
But tested in console application on i7 processor, and time 500ms?
It seems to me this is some delay.
|
|
|
|
|
There's also a "timeout" on NetworkStream.
I don't know if it has any relation to the timeout on TcpClient.
|
|
|
|
|
ReadTimeout NetStream returned GetStream() is same as TCPClient.ReceiveTimeout
|
|
|
|
|
Did you time the GetStream() separate from the Read()?
|
|
|
|
|
I tried it's, but time not changed.
|
|
|
|
|
Well, which took longer? The GetStream() or the Read() ... or you don't understand what I'm talking about.
|
|
|
|
|
GetStream() 0ms
Read() 530ms
|
|
|
|
|
Message Closed
modified 9-Sep-16 16:38pm.
|
|
|
|
|
This is a test of the CP Forum posting system. If this were an actual posting, it would include useful content and might provide some context for a question.
Seriously though, I'm not going to click your link. Please explain what you need assistance with in as much detail as you can provide.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
I want to avoid referencing anything related to VB if at all possible.
Is there a C# equivalent to Microsoft.VisualBasic.FileIO.TextFieldParser floating around anywhere?
EDIT ======================
As a quick fix, I came up with the following. I don't know what all the VB version does, but this code appears to correctly parse quoted strings...
public partial class TextFieldParser
{
public TextFieldParser()
{
}
public string[] ParseFields(string text)
{
string[] parts = text.Split(',');
List<string> newParts = new List<string>();
bool inQuotes = false;
string currentPart = string.Empty;
for (int i = 0; i < parts.Length; i++)
{
string part = parts[i];
inQuotes = (inQuotes || part.StartsWith("\""));
if (inQuotes)
{
currentPart = (string.IsNullOrEmpty(currentPart))? part : string.Format("{0},{1}", currentPart, part);
}
else
{
currentPart = part;
}
inQuotes = (inQuotes && !part.EndsWith("\""));
if (!inQuotes)
{
currentPart = currentPart.Replace("\"", "");
newParts.Add(currentPart);
currentPart = string.Empty;
}
}
return newParts.ToArray();
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 9-Sep-16 12:27pm.
|
|
|
|
|
For CSV / TDF files, I tend to use this library[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Actually, I'm writing a (evidently much lighter) CSV parser, and was gonna write an article, but now I don't know.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
Hi, I want to know in simple words,What is Assembly in Dotnet framework???
|
|
|
|
|
Plenty of definitions here[^].
This space for rent
|
|
|
|