I am trying to get the average time that it takes to add each element to an array of 5000 elements. I can get the time of each add operation in the loop, but am having trouble getting a running total so that I can calculate the average outside of the loop.
So far, i have the following code where I am printing the total
for (int i = 0; i < testData.length; i++) {
testData[i] = UUID.randomUUID().toString();
}
/****************************
* Linked List Set Unit Test
****************************/
long linked_add_time = 0;
long linked_add_total = 0;
for (int i = 0; i < 5000; i++){ // first 5000 elements used to measure average add time
linked_add_time = System.nanoTime();
linked.add(testData[i]);
linked_add_time = System.nanoTime() - linked_add_time;
linked_add_total =+ linked_add_time;
}
System.out.println(linked_add_total);
for (int i = 5000; i < testData.length; i++){
linked.add(testData[i]);
}