Skip to content

Instantly share code, notes, and snippets.

@frhack
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frhack/5db0485f9847e6b673be to your computer and use it in GitHub Desktop.
Save frhack/5db0485f9847e6b673be to your computer and use it in GitHub Desktop.
Java8 for ve forEach performance
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