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 / C++ / MFC
  4. how scope affects speed

how scope affects speed

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelplearning
7 Posts 5 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.
  • Z Offline
    Z Offline
    zildjohn01
    wrote on last edited by
    #1

    hi, i am getting started with a very resource intensive app, i was wondering if there is any speed difference between the following three versions of a function (assuming they are not inlined): int func1() {return 0;} namespace testns { int func2() {return 0;} }; class testclass { static int func3() {return 0;} }; void main() { func1(); testns::func2(); testclass::func3(); } any help is appreciated

    D M C Z 4 Replies Last reply
    0
    • Z zildjohn01

      hi, i am getting started with a very resource intensive app, i was wondering if there is any speed difference between the following three versions of a function (assuming they are not inlined): int func1() {return 0;} namespace testns { int func2() {return 0;} }; class testclass { static int func3() {return 0;} }; void main() { func1(); testns::func2(); testclass::func3(); } any help is appreciated

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      How you tried putting some timer code around each call, or running the code through the profiler to see?


      "Take only what you need and leave the land as you found it." - Native American Proverb

      1 Reply Last reply
      0
      • Z zildjohn01

        hi, i am getting started with a very resource intensive app, i was wondering if there is any speed difference between the following three versions of a function (assuming they are not inlined): int func1() {return 0;} namespace testns { int func2() {return 0;} }; class testclass { static int func3() {return 0;} }; void main() { func1(); testns::func2(); testclass::func3(); } any help is appreciated

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        me think scopes are resolved at compilation time, and will be converted to something similar.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        1 Reply Last reply
        0
        • Z zildjohn01

          hi, i am getting started with a very resource intensive app, i was wondering if there is any speed difference between the following three versions of a function (assuming they are not inlined): int func1() {return 0;} namespace testns { int func2() {return 0;} }; class testclass { static int func3() {return 0;} }; void main() { func1(); testns::func2(); testclass::func3(); } any help is appreciated

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          i vote for "no effect at all: they all turn into 'jmp xxxxx' after compilation" Cleek | Image Toolkits | Thumbnail maker

          N 1 Reply Last reply
          0
          • C Chris Losinger

            i vote for "no effect at all: they all turn into 'jmp xxxxx' after compilation" Cleek | Image Toolkits | Thumbnail maker

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            Chris Losinger wrote:

            they all turn into 'jmp xxxxx' after compilation

            or call instructions :-)

            1 Reply Last reply
            0
            • Z zildjohn01

              hi, i am getting started with a very resource intensive app, i was wondering if there is any speed difference between the following three versions of a function (assuming they are not inlined): int func1() {return 0;} namespace testns { int func2() {return 0;} }; class testclass { static int func3() {return 0;} }; void main() { func1(); testns::func2(); testclass::func3(); } any help is appreciated

              Z Offline
              Z Offline
              zildjohn01
              wrote on last edited by
              #6

              ok, thanks guys! i assumed instance member functions are a bit slower than static functions, is this correct too?

              C 1 Reply Last reply
              0
              • Z zildjohn01

                ok, thanks guys! i assumed instance member functions are a bit slower than static functions, is this correct too?

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #7

                zildjohn01 wrote:

                is this correct too?

                there's a minimal amount of extra setup required for member functions (need to push a 'this' pointer onto the stack - basically an extra parameter) before the call gets made. virtual functions will be slower because there's a function pointer lookup to deal with. Cleek | Image Toolkits | Thumbnail maker

                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