Last active
August 29, 2015 14:22
-
-
Save frhack/5db0485f9847e6b673be to your computer and use it in GitHub Desktop.
Java8 for ve forEach performance
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
Long timea; | |
Long timeb; | |
ArrayList<Integer> list = new ArrayList<Integer>(); | |
IntStream.range(1,100000).forEach((x) -> { | |
list.add(x); | |
}); | |
timea = System.nanoTime(); | |
for(int x : list){ | |
int y = x % 2 ; | |
} | |
timeb= System.nanoTime(); | |
System.out.println(timeb - timea); | |
timea = System.nanoTime(); | |
list.forEach((x) -> { | |
int y = x % 2; | |
}); | |
timeb= System.nanoTime(); | |
System.out.println(timeb - timea); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment