SE250:lab-1:jsmi233
Method
At first I tried using an addition without assignment (ie num1 + num2) but this didn't seem to do anything, so I included an assignment (ie result = num1 + num2) and included a constant assignment in the "empty" for loop.
Here is a description of what my code does.
All repetitions are achieved using for loops.
(1) Perform an assignment n times
(2) Perform an addition (including assignment) n times
(3) Subtract time taken for (1) from the time taken for (2)
(4) Repeat this five times and take an average
Results
These are just one set of results. In total, I had many varied results. All times are for a single addition in nanoseconds.
INT
Looping 10^8 times: 0.23
Looping 10^9 times: 0.097
LONG
Looping 10^8 times: 0.01
Looping 10^9 times: 0.03
SHORT
Looping 10^8 times: 0.49
Looping 10^9 times: 0.428
FLOAT
Looping 10^8 times: 0.08
Looping 10^9 times: 0.02
DOUBLE
Looping 10^8 times: 0.08
Looping 10^9 times: 0.053
Thoughts
It seems that all the types perform addition in about the same time. Why? It might be because I only added small values.
The exception to this is type short. This type seemed to take significantly longer. Why?