What's more easy for the machine?
-
Hello everybody. Today I was thinking about something very easy. What's more easy por the PC? My example is based in a ComboBox named "cb" Case 1:
if( cb.visible == true ){ cb.visible = false; }
case 2:cb.visible = false;
The idea is if check the current value of object before set this or set without evaluation. This maybe has not importance, but if you are building a big application should be considered. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE? -- modified at 1:43 Wednesday 18th January, 2006 -
Hello everybody. Today I was thinking about something very easy. What's more easy por the PC? My example is based in a ComboBox named "cb" Case 1:
if( cb.visible == true ){ cb.visible = false; }
case 2:cb.visible = false;
The idea is if check the current value of object before set this or set without evaluation. This maybe has not importance, but if you are building a big application should be considered. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE? -- modified at 1:43 Wednesday 18th January, 2006Well if you look at it logically, it is fairly obvious that the second case is faster. In the first case you must first access the memory to check the get the value and then compare in to the value on the other sisde of ==, and then finnaly assign it a new value. Where in the other case you just have one operation... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
-
Hello everybody. Today I was thinking about something very easy. What's more easy por the PC? My example is based in a ComboBox named "cb" Case 1:
if( cb.visible == true ){ cb.visible = false; }
case 2:cb.visible = false;
The idea is if check the current value of object before set this or set without evaluation. This maybe has not importance, but if you are building a big application should be considered. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE? -- modified at 1:43 Wednesday 18th January, 2006It depends. IF assigning value was some expensive operation (e.g. before you assign value to property some complex check is going on) THEN yes, it would be faster. In case when you simply assign value, second case is obviously faster. Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
Well if you look at it logically, it is fairly obvious that the second case is faster. In the first case you must first access the memory to check the get the value and then compare in to the value on the other sisde of ==, and then finnaly assign it a new value. Where in the other case you just have one operation... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
You are forgetting something. The Visible property is not just a memory location, it's a property. It does quite a lot more than just changing a single memory location. When getting the value, the Visibe property calls Control.GetVisibleCore to get the value from the state of the control. When setting the value, the Visible property calls Control.SetVisibleCore to update the control. One of the first things that SetVisibleCore does, is to call GetVisibleCore to check if the operation will change the value of the property. If it won't, the method skips changing the visual apperance of the control and just updates the state of the control. The first case is faster if the property doesn't change value, and the second case is faster if the property does change value. So which method is faster depends on the probability of the property to change value. If you want it really fast, you'll keep a local copy of the value of the Visible property, and check that value before changing the actual property. --- b { font-weight: normal; } -- modified at 3:52 Wednesday 18th January, 2006
-
Well if you look at it logically, it is fairly obvious that the second case is faster. In the first case you must first access the memory to check the get the value and then compare in to the value on the other sisde of ==, and then finnaly assign it a new value. Where in the other case you just have one operation... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
-
It depends. IF assigning value was some expensive operation (e.g. before you assign value to property some complex check is going on) THEN yes, it would be faster. In case when you simply assign value, second case is obviously faster. Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
Well if you look at it logically, it is fairly obvious that the second case is faster. In the first case you must first access the memory to check the get the value and then compare in to the value on the other sisde of ==, and then finnaly assign it a new value. Where in the other case you just have one operation... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!