Why lambda comparator is so slow?


  • 0
    X
            Arrays.sort(people, (a, b) -> a[0] != b[0] ? b[0] - a[0] : a[1] - b[1]);
    

    85ms

            Arrays.sort(people, new Comparator<int[]>() {
                @Override
                public int compare(int[] p1, int[] p2) {
                    if (p1[0] != p2[0]) {
                        return p2[0] - p1[0]; // descending in height
                    } else {
                        return p1[1] - p2[1]; // ascending in # of people ahead
                    }
                }
            });
    

    19ms


  • 0
    C

    I noticed the same thing too. It looks a lot more elegant but it drags the performance down


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.