Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javadaemon.skrollr.test;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- public class ListSpeedTest {
- public static double testList(List<Integer> list, int testAmount, int testTries) {
- ArrayList<Long> results = new ArrayList<Long>();
- for(int counter = 0; counter < testTries; counter++) {
- long beforeTime = System.nanoTime();
- addToList(list, testAmount);
- long afterTime = System.nanoTime();
- long timeSpent = afterTime - beforeTime;
- list.clear();
- results.add(new Long(timeSpent));
- }
- long sum = 0;
- for (Long e : results) {
- sum += e;
- }
- return sum/results.size();
- }
- public static void addToList(List<Integer> list, int amount) {
- for(int counter = 0; counter < amount; counter++) {
- list.add(new Integer(counter));
- }
- }
- public static void main(String[] args) {
- ArrayList<Integer> arrayList = new ArrayList<Integer>();
- LinkedList<Integer> linkedList = new LinkedList<Integer>();
- double arrayTest = testList(arrayList, 1000000, 10);
- double linkedTest = testList(linkedList, 1000000, 10);
- System.out.println("arrayTest avarage: "+arrayTest);
- System.out.println("linkedTest avarage: "+linkedTest);
- }
- }
Add Comment
Please, Sign In to add comment