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. The Lounge
  3. Do you think much about your shorts?

Do you think much about your shorts?

Scheduled Pinned Locked Moved The Lounge
csharpasp-netcomdata-structuresperformance
38 Posts 18 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.
  • C Chris Losinger

    I mean: where does the code in question run? And what does the compiler generate, and how does that mesh with the target CPU? If it's hardware that's going to space, it's probably not running on a common commercial CPU, so you can't make assumptions about word size and what a 'short' is, etc.. [I don't actually know which code you're talking about]

    Gerry Schmitz wrote:

    And refactoring is not an option?

    if it's commented as being there for performance reasons, you can probably assume it was profiled and tested for performance.

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

    You make a lot of assumptions.

    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

    C O 2 Replies Last reply
    0
    • J Joan M

      Working in industrial sector... there are still devices that struggle with memory and therefore I use BYTES for counters when I can, same for the states machine controller variable... So for me it's a yes.

      www.robotecnik.com[^] - robots, CNC and PLC programming

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

      I worked with PLC's, etc. Never had to sweat 1 or 2 bytes; getting the storage architecture right was more important.

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      J N 2 Replies Last reply
      0
      • L Lost User

        You make a lot of assumptions.

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

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

        WTF. if you don't know anything about the hardware that runs it, you can't make assumptions about the software.

        L 1 Reply Last reply
        0
        • L Lost User

          Well,

          Gerry Schmitz wrote:

          In some cases, their loop variable is an int; in others a short; in others a long.

          Modern compilers will promote those loop variables to 32/64 bit depending on target architecture. If you are looking at old code... there were reasons to use integer BOOL for performance and 8 bit bool for smaller code-size many years ago. Optimizing compilers today make most of that pointless. I am finally getting around to reviewing that json library @code-witch keeps obsessing over. First thing I noticed was the liberal use of bool. But in the end... it does't really matter the compiler should promote some of these. Best Wishes, -David Delaune

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #14

          I expect promotion. The reason I use things like bytes and half words is so they fit better on 8bit. I am expecting a lot out of it in terms optimization on a 32 or 64 bit machine. My code favors 8bit it as a result

          Real programmers use butterflies

          L 1 Reply Last reply
          0
          • L Lost User

            Well,

            Gerry Schmitz wrote:

            In some cases, their loop variable is an int; in others a short; in others a long.

            Modern compilers will promote those loop variables to 32/64 bit depending on target architecture. If you are looking at old code... there were reasons to use integer BOOL for performance and 8 bit bool for smaller code-size many years ago. Optimizing compilers today make most of that pointless. I am finally getting around to reviewing that json library @code-witch keeps obsessing over. First thing I noticed was the liberal use of bool. But in the end... it does't really matter the compiler should promote some of these. Best Wishes, -David Delaune

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

            I have the whole application up and running and have gone through all the code and docs. They use random access binary files containing millions of doubles. Storage is / was not a problem. I thought it was an interesting mental exercise in light of some of the "performance" discussions going on. Nothing more. We can all stop "thinking" now.

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

            1 Reply Last reply
            0
            • L Lost User

              In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #16

              Depends on the processor: a lot of NASA stuff was for seriously old processors - for example the US military did use some Z80 based stuff right up to the end of the century, so it's possible NASA did as well. And like many other processors of it's age, the Z80 had eight bit and sixteen bit registers: a "tight loop" could optimise to a DJNZ operation (using an 8 bit register) or an LDI / LDD / LDIR / LDDR (using sixteen bit). If your loop needed a 32 bit integer, then machine code got a lot more complex. So variable size choice could easily have a bit effect on performance - and given the old processors ran as speed we would consider unacceptable for a digital watch these days every little helped! :laugh:

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              L 1 Reply Last reply
              0
              • C Chris Losinger

                WTF. if you don't know anything about the hardware that runs it, you can't make assumptions about the software.

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

                It can run on anything with a C compiler. I could put it on my phone / watch.

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                C 1 Reply Last reply
                0
                • H honey the codewitch

                  I expect promotion. The reason I use things like bytes and half words is so they fit better on 8bit. I am expecting a lot out of it in terms optimization on a 32 or 64 bit machine. My code favors 8bit it as a result

                  Real programmers use butterflies

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

                  Oh Well, I wish you would have commented sooner. I found a bug in your json parser but didn't want to tarnish your article comment section. :-O Let me know if you want to discuss it here and I'll go over and delete it.

                  H 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    Depends on the processor: a lot of NASA stuff was for seriously old processors - for example the US military did use some Z80 based stuff right up to the end of the century, so it's possible NASA did as well. And like many other processors of it's age, the Z80 had eight bit and sixteen bit registers: a "tight loop" could optimise to a DJNZ operation (using an 8 bit register) or an LDI / LDD / LDIR / LDDR (using sixteen bit). If your loop needed a 32 bit integer, then machine code got a lot more complex. So variable size choice could easily have a bit effect on performance - and given the old processors ran as speed we would consider unacceptable for a digital watch these days every little helped! :laugh:

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

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

                    It was ported from Fortran to C in 1993; not exactly the dark ages. "High performance" update (double doubles) around 2013. [JPL Planetary and Lunar Ephemerides](https://ssd.jpl.nasa.gov/?planet\_eph\_export) (This whole thing started because I made a solar calendar and said it was "accurate"; which begged the question "how accurate", etc. Anyway, I do a lot of calcs in real-time for a simulation; ergo...)

                    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                    1 Reply Last reply
                    0
                    • L Lost User

                      It can run on anything with a C compiler. I could put it on my phone / watch.

                      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

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

                      maybe it can run on anything with a C compiler ... as long as it was deliberately written to work on any OS with any CRT implementation, using no system-specific libraries, and making no assumptions about the underlying hardware. :laugh: :laugh: :laugh: the C spec only specifies minimum sizes for short, int and long. int and short must be at least 16 bits. long must be at least 32 bits. so what any of those types means in terms of storage and CPU handling (aka performance) depends on the compiler and the target architecture.

                      L 1 Reply Last reply
                      0
                      • L Lost User

                        I worked with PLC's, etc. Never had to sweat 1 or 2 bytes; getting the storage architecture right was more important.

                        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                        J Offline
                        J Offline
                        Joan M
                        wrote on last edited by
                        #21

                        Lucky you. If I choose the material to be used I never have to... but when the customer gives me the material then everything can happen.

                        www.robotecnik.com[^] - robots, CNC and PLC programming

                        L 1 Reply Last reply
                        0
                        • J Joan M

                          Lucky you. If I choose the material to be used I never have to... but when the customer gives me the material then everything can happen.

                          www.robotecnik.com[^] - robots, CNC and PLC programming

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

                          The customer ordered it, the hardware company built it, I had to program it (contract). There were no choices. The hardware company used my software to debug their firmware. (Only way to avoid finger pointing).

                          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                          J 1 Reply Last reply
                          0
                          • C Chris Losinger

                            maybe it can run on anything with a C compiler ... as long as it was deliberately written to work on any OS with any CRT implementation, using no system-specific libraries, and making no assumptions about the underlying hardware. :laugh: :laugh: :laugh: the C spec only specifies minimum sizes for short, int and long. int and short must be at least 16 bits. long must be at least 32 bits. so what any of those types means in terms of storage and CPU handling (aka performance) depends on the compiler and the target architecture.

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

                            They've built a Python shell for it. Does that help or confuse?

                            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                            1 Reply Last reply
                            0
                            • L Lost User

                              The customer ordered it, the hardware company built it, I had to program it (contract). There were no choices. The hardware company used my software to debug their firmware. (Only way to avoid finger pointing).

                              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                              J Offline
                              J Offline
                              Joan M
                              wrote on last edited by
                              #24

                              I'm glad you've been so lucky. Congratulations. :thumbsup:

                              www.robotecnik.com[^] - robots, CNC and PLC programming

                              1 Reply Last reply
                              0
                              • L Lost User

                                In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                D Offline
                                D Offline
                                Daniel Pfeffer
                                wrote on last edited by
                                #25

                                Only when targeting (a) an extremely memory-limited system, or (b) a 16-bit or less processor. (a) may be the case with industrial controllers or the first stage of a bool loader (it is an advantage if the code can run in the processor's internal memory) (b) may be the case for some embedded devices

                                Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                L 1 Reply Last reply
                                0
                                • L Lost User

                                  "Not thinking" is not something I ever boasted about. It was a thought exercise; regardless of what the compiler "might do".

                                  It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                  S Offline
                                  S Offline
                                  Slacker007
                                  wrote on last edited by
                                  #26

                                  an int is just fine. for me, it is a no brainer. If you want to spend hours thinking about it, go for it.

                                  1 Reply Last reply
                                  0
                                  • D Daniel Pfeffer

                                    Only when targeting (a) an extremely memory-limited system, or (b) a 16-bit or less processor. (a) may be the case with industrial controllers or the first stage of a bool loader (it is an advantage if the code can run in the processor's internal memory) (b) may be the case for some embedded devices

                                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

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

                                    Yes. My first job was an IBM installation. Little signboards around the office, and all they said was "Think". One of the few joys left in life when you can.

                                    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      I worked with PLC's, etc. Never had to sweat 1 or 2 bytes; getting the storage architecture right was more important.

                                      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                      N Offline
                                      N Offline
                                      Nelek
                                      wrote on last edited by
                                      #28

                                      I have always preferred the 2 bytes distribution for variables (WORD or INT) due to the endian changes, it is already painful enough to deal with it without having to increase the difficulty messing with more than a variable in the "same space" On the other hand, when staying in the PLC I have used a lot of BYTE variables. Specially when grouping bits to be masked or moved from one place to another.

                                      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                      1 Reply Last reply
                                      0
                                      • L Lost User

                                        In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                                        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                        M Offline
                                        M Offline
                                        Mike Hankey
                                        wrote on last edited by
                                        #29

                                        More so now because of winter my legs are shockingly white.

                                        I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                                          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                          R Offline
                                          R Offline
                                          Rick York
                                          wrote on last edited by
                                          #30

                                          It depends on the target environment. I work on HPC stuff using CUDA and GPUs and with them using a short instead of an int can make a significant difference in performance and Nvidia includes this point in their documentation. With CUDA, using an signed value is almost always preferred over an unsigned value for performance reasons also. They have quite a number of odd, little quirks regarding optimal performance. For standard desktop CPUs I rarely concern myself with that issue. The only other environment I work in these days is embedded code in scanning cameras and I don't care there either.

                                          "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                                          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