Skip to content

Instantly share code, notes, and snippets.

@YannickFricke
Created November 4, 2016 11:31
Show Gist options
  • Save YannickFricke/d30f1bdc982cfa53810a0dbf29fbcf03 to your computer and use it in GitHub Desktop.
Save YannickFricke/d30f1bdc982cfa53810a0dbf29fbcf03 to your computer and use it in GitHub Desktop.
Java Performance Test
package javaperf;
import java.util.*;
public class JavaPerf
{
private static Map<Integer, UUID> uuidMap = new HashMap<>();
private static List<UUID> uuids = new ArrayList<>();
public static void main(String[] args)
{
for (int i = 0; i < 100000; i++)
{
UUID uuid = UUID.randomUUID();
uuidMap.put(i, uuid);
uuids.add(uuid);
}
Random random = new Random();
int index = random.nextInt(uuids.size() - 1);
// Map test
long mapOne = System.currentTimeMillis();
System.out.println(String.format("Value of index %d is: %s", index, uuidMap.get(index).toString()));
long mapTest = System.currentTimeMillis() - mapOne;
long listOne = System.currentTimeMillis();
System.out.println(String.format("Value of index %d is: %s", index, uuids.get(index).toString()));
long listTest = System.currentTimeMillis() - listOne;
System.out.println("Map index: " + mapTest);
System.out.println("List index: " + listTest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment