Search for question
Question

1.1 Task 1

The first task involves contrasting the performance of programs with and without caching. In particular,

you will be working with the volatile keyword in Java. The volatile keyword informs the compiler

that the variable should not be cached and accesses should always go to main memory.

You will run two separate loops, one when the loop variable is volatile and one for the loop variable

is not volatile. You will loop number of times for both loops, so if size is 5 your loops will run

5 times.

Your loop must do something on top of incrementing the loop variable, the loops will maintain a running

total of the addition and subtraction operations using the loop variable. The choice of whether you

perform an addition or subtraction to the runningTotal is based on whether the loop variable is odd or

even for the given iteration. If the loop variable is even (e.g., 10) then you should add the loop variable

to the runningTotal; if the loop variable is odd (e.g., 37) then you should subtract the loop variable

from the runningTotal. To cope with potential overflows/underflows runningTotal should be a long

variable type.

You will do this number of times, then calculate the average time

(totalTime/experiments) that it took to perform operations on runningTotal for both loops. You will

also calculate the average sum for all experiments (totalSum/experiments) for both loops.

You will then output the statistics for each of these loops. You will print out the average time taken to

perform the loop with the regular and volatile variable. Then you will print out the running totals that

each of these loops maintained. These numbers should be the same as both loops run for the number

of times(). Look at the example output below to see more on how these numbers are outputted

to the terminal.

Produce a short report (450-500 words) with graphs and/or tables describing the observed behavior

when using the volatile keyword versus without.

Fig: 1