企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
###Lambda性能### * 排序:单CPU环境下lambda排序比Collections提供的排序方法慢 ``` public class Appliction { public static void main(String[] args) { Random random = new Random(); List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 2000000; i++) { list.add(random.nextInt()); } long beginTime = System.currentTimeMillis(); List<Integer> collect = list.stream().sorted((a, b) -> a.compareTo(b)).collect(Collectors.toList()); System.err.println(System.currentTimeMillis() - beginTime); long c2 = System.currentTimeMillis(); Collections.sort(list); System.err.println(System.currentTimeMillis() - c2); } private static Integer max(List<Integer> list) { Integer min = Integer.MIN_VALUE; for (Integer i : list) { min = Integer.max(i, min); } return min; } } out =====> 1025 // lamdba排序 759 ``` * 查找 ``` public class Appliction { public static void main(String[] args) { Random random = new Random(); List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 2000000; i++) { list.add(random.nextInt()); } long beginTime = System.currentTimeMillis(); Integer max = list.stream().max((a, b) -> a.compareTo(b)).get(); System.err.println(System.currentTimeMillis() - beginTime); System.err.println(max); long c2 = System.currentTimeMillis(); Integer max2 = max(list); System.err.println(System.currentTimeMillis() - c2); System.err.println(max2); } private static Integer max(List<Integer> list) { Integer min = Integer.MIN_VALUE; for (Integer i : list) { min = Integer.max(i, min); } return min; } } out =====> 116 // lambda查找 2147472958 23 2147472958 ```