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. strange behavior

strange behavior

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
4 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.
  • H Offline
    H Offline
    Haoman17
    wrote on last edited by
    #1

    I see a BIG DIFFERENT in performance, between the following 2 methoods, WHY IS THAT?: ---------------Method 1----------------------------- Class { Member x Function() { Write to x; } } Main() { Call function() } --------------Method 2:-------------------------------- Class { Function(member x) { Write to the member x; } } Main() { Member x ; Call function (x) }

    C J Z 3 Replies Last reply
    0
    • H Haoman17

      I see a BIG DIFFERENT in performance, between the following 2 methoods, WHY IS THAT?: ---------------Method 1----------------------------- Class { Member x Function() { Write to x; } } Main() { Call function() } --------------Method 2:-------------------------------- Class { Function(member x) { Write to the member x; } } Main() { Member x ; Call function (x) }

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

      Haoman17 wrote:

      I see a BIG DIFFERENT in performance, between the following 2 methoods,

      if the second method is faster, it could be because the constructor or destructor of 'Member' takes a long time. if the first method is faster, it could be because you're doing a deep copy of 'x' when passing it.

      image processing | blogging

      1 Reply Last reply
      0
      • H Haoman17

        I see a BIG DIFFERENT in performance, between the following 2 methoods, WHY IS THAT?: ---------------Method 1----------------------------- Class { Member x Function() { Write to x; } } Main() { Call function() } --------------Method 2:-------------------------------- Class { Function(member x) { Write to the member x; } } Main() { Member x ; Call function (x) }

        J Offline
        J Offline
        Jun Du
        wrote on last edited by
        #3

        Could you post the code you used in the testing?

        Best, Jun

        1 Reply Last reply
        0
        • H Haoman17

          I see a BIG DIFFERENT in performance, between the following 2 methoods, WHY IS THAT?: ---------------Method 1----------------------------- Class { Member x Function() { Write to x; } } Main() { Call function() } --------------Method 2:-------------------------------- Class { Function(member x) { Write to the member x; } } Main() { Member x ; Call function (x) }

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          They will execute at the same speed if you pass x by reference in Method 2. Otherwise, if Member is a complex datatype, Method 2 will run slower since it has to copy the value of x into the function before entering the function.

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          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