Microbenchmarks in Java

Microbenchmarking is an important way of improving the fine bits of code that programmers use to carry out much larger functions. We start off with a simple example, which signifies how a microbenchmark will perform in Java:

import java.util.ArrayList;import java.util.LinkedList;import java.util.List; public class SimpleMicroBenchmark {    public static Long buildTimeForArrayList = 0l;    public static Long buildTimeForLinkedList = 0l;        public static void main(String[] args) {        System.out.println("Building an ArrayList with 10,000 elements" );        System.out.println("--------build test----------" );        List<Integer> arrayList = buildList("ArrayList",new ArrayList<Integer>(), 10000 ); List<Integer> linkedList = buildList("LinkedList",new ...

Get Java 9 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.