There was such a situation, parsing HTML using jsoup (1.7.3), the isUse method accepts Element and returns whether it is suitable for further work (there are a bunch of <article> tags). I am writing in Java 8 and I thought to use new ones:
List<Element> news = items.stream().filter(e -> isUse(e)).collect(Collectors.toList()); Everything works, this code does not cause any questions, but I thought to compare with the usual cycle:
List<Element> news = new ArrayList<>(); for (Element e : items) if (isPodcast(e)) news.add(e); And it turns out that option 2 approximately 2 - 1.5 times always works faster. Java version:
java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode) OS: mac os x 10.9.3. I tried on Windows 7 x64 with java8u5.
PS It’s not that the difference in 60 - 80 ms strongly strains me, I just wonder why.
isUse()in one case andisUse()in the other? Is it because of this that the speed changes? - Jofsey