-
-
Save zivce/8f2a3d3be193eac2a00118640407b016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// excerpt from the benchmark | |
@Warmup(iterations = 50, time = 2, timeUnit = TimeUnit.MILLISECONDS) | |
@Measurement(iterations = 3, time = 2, timeUnit = TimeUnit.MILLISECONDS) | |
@Fork(1) | |
@State(Scope.Benchmark) | |
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |
@BenchmarkMode({ Mode.AverageTime}) | |
public class Collections9 { | |
private static ArrayList<Cat> cats = new ArrayList<>(); | |
private static List<String> cats9; | |
private static List<String> cats8; | |
@Benchmark | |
public void catsNonJava9Way(){ | |
addCat("George"); | |
addCat("John"); | |
addCat("Mack"); | |
addCat("Other"); | |
addCat("Lorem"); | |
for(Cat cat : cats) { | |
cat.print(); | |
} | |
} | |
@Benchmark | |
public void catsJava8Way() { | |
// as seen on https://openjdk.java.net/jeps/269 | |
cats8 = Collections.unmodifiableList(Stream.of("George", "John", "Mack", "Other", "Lorem").collect(Collectors.toList())); | |
cats8.forEach(System.out::println); | |
} | |
@Benchmark | |
public void catsJava9Way(){ | |
cats9 = List.of("George", "John", "Mack", "Other", "Lorem"); | |
cats9.forEach(System.out::println); | |
} | |
public void addCat(String name) { | |
cats.add(new Cat(name)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment