dinomugM to Java™ Community • 2 years agoThe cost of Java's EnumSetnullprogram.commessage-square5arrow-up15arrow-down10
arrow-up15arrow-down1external-linkThe cost of Java's EnumSetnullprogram.comdinomugM to Java™ Community • 2 years agomessage-square5
minus-squareTaldenNZlinkfedilink3•edit-211 months agoThe 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.
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.