Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What's more easy for the machine?

What's more easy for the machine?

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shopi30
    wrote on last edited by
    #1

    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

    C D 2 Replies Last reply
    0
    • S shopi30

      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

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      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!

      G S 3 Replies Last reply
      0
      • S shopi30

        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

        D Offline
        D Offline
        DavidNohejl
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • C CWIZO

          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!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C CWIZO

            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!

            S Offline
            S Offline
            shopi30
            wrote on last edited by
            #5

            Thanks! it's the same that I was thinking! ;) Have a nice week!. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

            1 Reply Last reply
            0
            • D DavidNohejl

              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

              S Offline
              S Offline
              shopi30
              wrote on last edited by
              #6

              Thanks dnh! it's the same that I was thinking! ;) Have a nice week!. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

              1 Reply Last reply
              0
              • C CWIZO

                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!

                S Offline
                S Offline
                shopi30
                wrote on last edited by
                #7

                Thanks CWIZO! it's the same that I was thinking! ;) Have a nice week!. SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups