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. time performance -global or local

time performance -global or local

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
7 Posts 3 Posters 1 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.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    MCU program, no cache, can anybody explain the performance comparison between global and local variables?

    L A 2 Replies Last reply
    0
    • E econy

      MCU program, no cache, can anybody explain the performance comparison between global and local variables?

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

      Your question is far from clear; does it have anything to do with C/C++/MFC?

      Veni, vidi, abiit domum

      E 2 Replies Last reply
      0
      • L Lost User

        Your question is far from clear; does it have anything to do with C/C++/MFC?

        Veni, vidi, abiit domum

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        I just not very clear which way is better in programming a C program, that will run on a 32 bit RISC Microcontroller platform. Using globals or using locals as possible as many.

        1 Reply Last reply
        0
        • L Lost User

          Your question is far from clear; does it have anything to do with C/C++/MFC?

          Veni, vidi, abiit domum

          E Offline
          E Offline
          econy
          wrote on last edited by
          #4

          as I understand, local in stack, and possibly replaced by register. but local variable needs push/pop operation. Globals in RAM, no need to allocate memory/retrieve memory every time

          L 1 Reply Last reply
          0
          • E econy

            as I understand, local in stack, and possibly replaced by register. but local variable needs push/pop operation. Globals in RAM, no need to allocate memory/retrieve memory every time

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

            Given the speed of most modern processors the time difference will most likely be too small to measure.

            Veni, vidi, abiit domum

            1 Reply Last reply
            0
            • E econy

              MCU program, no cache, can anybody explain the performance comparison between global and local variables?

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              It depends on the architecture and how quickly the processor can form an address in comparison to how fast an instruction gets through the pipeline. The only way you're going to know for sure is to measure the speed of your app using both types of variables.

              E 1 Reply Last reply
              0
              • A Aescleal

                It depends on the architecture and how quickly the processor can form an address in comparison to how fast an instruction gets through the pipeline. The only way you're going to know for sure is to measure the speed of your app using both types of variables.

                E Offline
                E Offline
                econy
                wrote on last edited by
                #7

                If a code block locates in an infinite loop, choose locals, then with locality principle, it is better than globals, I think. If a code blcck just run a few times, accessing global vs push/pop stack operation, which one is better?

                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