|
For what its worth, I just ran a test and got the following results. It looks like it doesn't matter for something this small.
Inside the loop took 552645639 ticks.
Outside the loop took 549520699 ticks.
The test code:
long timeIn = 0;<br />
long timeOut = 0;<br />
<br />
long l = System.DateTime.Now.Ticks;<br />
for (long x = 0; x < 10000000000; x++)<br />
{<br />
int i = 1;<br />
i++;<br />
}<br />
timeIn = System.DateTime.Now.Ticks - l;<br />
<br />
l = System.DateTime.Now.Ticks;<br />
int i2;<br />
for (long x = 0; x < 10000000000; x++)<br />
{<br />
i2 = 1;<br />
i2++;<br />
}<br />
timeOut = System.DateTime.Now.Ticks - l;<br />
<br />
MessageBox.Show("Time In: " + timeIn.ToString() + Environment.NewLine + "Time Out: " + timeOut.ToString());<br />
Hogan
|
|
|
|
|
Indeed, I found the same thing last week.
|
|
|
|
|
So the measured difference is less than 1% which is I guess well below
your measurement accuracy: you are measuring elapsed time (good) over
a long period (50 sec, good), but circumstances vary: there are hundreds
of threads in an idle system, watching each and every part of your machine,
there are disk transfers with DMA, there is a varying amount of Ethernet
traffic including broadcast messages you are not interested in, etc etc.
So my first impression is the execution times are the same.
What you could do is reduce the loop count by a factor of 100, run it
100 times, and observe the distribution of the 100 timing results.
The disappointment is neither the C# compiler nor the JIT compiler was
smart enough to recognize the entire loop body could and should be moved
outside, and then the loop is without subject; so it should have been
hundred ticks at most !
On a non-CLR language (such as good old C) it takes quite some tricks
to prevent the compiler from throwing it all out, and still get an
accurate measurement !
|
|
|
|
|
Hi,
This is related to the formatting, not the topic, of your message.
I am preparing an article on copying code snippets from a CodeProject message board to
Visual Studio; seems there are no problems when the browser used is FireFox, Safari, ...
but often problems arise when using Internet Explorer.
One of the factors is the tags that are present inside the < PRE> </PRE> block.
In your message the lines are separated by <br> tags; most other messages have
just regular newlines.
Could you please tell me how you get that, i.e. what tools you use, and how you go
about it. Thanks in advance.
|
|
|
|
|
I'm not really sure if I understood what you mean, hence I don't know if this is the answer your after...
I use Maxthon browser, and when inserting code snippets to my posts I wrap the <code></code> tags inside of the <pre></pre> tags, and not the other way around.
If you could explain again, maybe I would be able to give you a better answer.
Regards,
Shy.
|
|
|
|
|
Thanks, that is exactly what I wanted to know.
I am not familiar with Maxthon browser, I never heard of it.
The background is: if I select (part of) your code snippet using Internet Explorer,
then copy it in Visual Studio, all formatting is lost, there are no line breaks
any more.
I created a utility that improves the situation in most cases; with it I
manage to get newlines, and most of the time the indentation remains intact too;
on your code snippet, with the tool, I do get newlines (so that is an
improvement) but now I loose indentation.
My article will suggest people use the PRE tags without adding CODE tags to it;
could you please give that a try, so just reply to this message, and insert
a code snippet as you usually do (that is using PRE tags) but this time
without using CODE tags.
Thanks in advance.
|
|
|
|
|
Hi All,
I have 2 project in my workspace - first one is some old project that was written in visual C++ and the second one is some project that i writing now in visual C# ( using visual studio 2005 ).
I need to call some method (static method ) and using some enum and even create some object that i have in the C++ project.
My question is how i create the connection between them ?
How can i "include" the classes from C++ in my C# project ?
Thanks for any help.
|
|
|
|
|
Compile your C++ project with the /clr compiler switch. Make your C++ classes be ref classes. Then you can talk to them and instantiate them just fine from any .NET language, including C#.
For more information, see this article on C++/CLI[^].
|
|
|
|
|
Can i do it without compile my C++ project with clr on ?
I don't want to change anything in the C++ project - This project was develop with visual studio 6 and i cant touch the source code.
|
|
|
|
|
There are really 3 ways of dealing with native code in C#:
- P/Invoke[^]: allows you to call exported C functions (not C++ class member functions).
- C++/CLI like I just mentioned
- COM interop: if the C++ dll compiles into a COM object, you can use it easily from C# by simply adding a reference to the COM object like you would a normal .NET control.
If you can't touch the C++ code, could you instead build a new C++/CLI dll that uses the native C++ class under the hood? That way, your C# could talk to the C++/CLI just fine, and under the hood your C++/CLI calls would just go to the native C++ classes.
|
|
|
|
|
Hello all, I am working on debugging a web application. I need to make a boolean value equal to true, false or null. Is it possible to make it null?
|
|
|
|
|
I don't believe you can set a boolean to null. Why do you need to set it to null, why will false not suffice?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Justin Perez wrote: Why do you need to set it to null, why will false not suffice?
I would imaging that something can be true, something can be false and something can be unknown (hence null). There is a distict semantic difference between false and unknown.
I used a language, many years ago, that had the key words true , false and maybe which was used by functions like PointInPolygon(somePoint, somePolygon) the result was true if the point was inside the polygon, false if outside the polygon and maybe if it was on the line.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
|
Duh, same as setting an int to null
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
You should set set it to false. Boolean is supposed to hold either true or false.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
If he's going to be grabbing the value from a database, null could be a "valid" entry.
|
|
|
|
|
There is always that possibility. But based on his reply to this post, I am not sure if that's the case.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Then you can use DBNull. That's the whole reason that class exists.
|
|
|
|
|
The problem is that the application is already built to use boolean values. The user has a section where they chose an option from two drop down boxes. Based on what they select there are two check boxes that are either enabled or not. The user wants to see the results of these choices in the reporting as true equal yes and false equaling no and if it is not enabled they want it to show a blank.
the way that it is designed right now is it uses a findcontrol on the check boxes, which returns true or false no matter if it is enabled or not. It then takes that true/false and puts it into the database table. I first thought to just put the assignment into an if statement checking to see if it is enabled. If not then I would not assign anything to that value in the table. This will work for the first time creation of this but the user can go back later and change their answers and this will not change the value that is in the table.
|
|
|
|
|
I can think of some situation where I might really want a boolean, but to know that it hasn't been initialized yet. Nullable boolean makes sense sometimes.
|
|
|
|
|
Here is part of the code that I am talking about:
CheckBox chkPU = (CheckBox)dgi.FindControl(c_grd_ctrl_id_chkPU);
CheckBox chkCP = (CheckBox)dgi.FindControl(c_grd_ctrl_id_chkCP);
.
.
.
.
vudr.INCL_PERS_USE_IND = chkPU.Checked;
vudr.COMN_CRY_PSGR_IND = chkCP.Checked;
|
|
|
|
|
ltmnm wrote: it is not enabled
If it is the checkbox that you are talking about, then you have to check the enabled property if it is true or false. If you need to have the dropdown show a blank when the checkbox is not enabled, then you just need to add the logic to check for that. Don't confuse Checked property with Enabled ...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Sorry, I should be more clear. The drop down boxes are just answers that go into the database. the code also checks to see if the check boxes are checked and then stores that in the database as well. It returns false when the check box is not checked even if the check box is not enabled. The data that is in the table is then queried and used for reporting services. In those reports the user wants to see yes when the check box is checked and no when it is not. They also want to see just a blank for when the check box was not enabled. So, I am just trying to see if there is a way to make a boolean value equal true, false and anything else that could represent the check box not being enabled.
Hope that helps clear things up a little.
thank you for all your help.
|
|
|
|
|
The only way you can represent the checkbox not being enabled is testing for CheckBox.Enabled = false ...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|