• TaldenNZ
    link
    2
    edit-2
    11 months ago

    The code here is somewhat contrived in favour of the ints. Taking the meat of the | example…

        int a = A | B | G;
        for (int i = 0; i < 1_000_000_000; i++) {
            int b = A | B | G;
            assert a == b;
        }
    

    This is actually compiled as

        int a = 67;
        for (int i = 0; i < 1_000_000_000; i++) {
            int b = 67;
            assert a == b;
        }
    

    The compiler should trivially identify that a == b is always true.

    This simple change to the Enum case brings it to within 3x the int scenario…

        Set<Flag> a = EnumSet.of(Flag.A, Flag.B, Flag.G);
        Set<Flag> b = EnumSet.of(Flag.A, Flag.B, Flag.G);
        for (int i = 0; i < 1_000_000_000; i++) {
            assert a.equals(b);
        }
    

    A better range of benchmark cases is required.