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