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. Boolean Optimization

Boolean Optimization

Scheduled Pinned Locked Moved C#
performancedatabasealgorithmsquestioncode-review
3 Posts 3 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax

    If (complicated boolean statement)
    {
    form.attribute = true;
    }
    else
    {
    form.attribute = false;
    }

    I was wondering whether using something like this would make any difference

    form.attribute = complicated boolean statement.

    Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?

    L G 2 Replies Last reply
    0
    • D Drew McGhie

      I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax

      If (complicated boolean statement)
      {
      form.attribute = true;
      }
      else
      {
      form.attribute = false;
      }

      I was wondering whether using something like this would make any difference

      form.attribute = complicated boolean statement.

      Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can safely remove the if-else clause, but it won't result in a noticable performance increase. regards

      1 Reply Last reply
      0
      • D Drew McGhie

        I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax

        If (complicated boolean statement)
        {
        form.attribute = true;
        }
        else
        {
        form.attribute = false;
        }

        I was wondering whether using something like this would make any difference

        form.attribute = complicated boolean statement.

        Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?

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

        The difference in performance is so very small that it's more a matter of taste and style. The second code is a bit more efficient, mainly because it doesn't contain a jump. If you only run the code a hundred times though, the difference in execution time is so small that it's not even possible to measure. --- b { font-weight: normal; }

        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