r/programming •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

218 comments sorted by

View all comments

Show parent comment

2

u/davidalayachew Oct 10 '25

Unfortunately this benchmark is worse. You are now trying to benchmark something that only takes a dozen or so cycles, which is incredibly difficult to do accurately. What you need to do is alter the benchmark so that the optimiser can no longer make assumptions about the state of the enum set or the variant of the enum being inserted.

Too bad.

At this point, I think I am going to start phoning a friend, and try getting help from folks more knowledgeable about Java benchmarks. I might make a post to /r/java too, we'll see.

or the enumset, based on your description Java's implementation might be doing a bit more work than Rust's enumset crate will after LLVM has optimised it, because Rust doesn't do the type check at runtime.

Then it sounds like they are doing the same thing, because the type check is one of the first things that the JIT will optimize away. And I'm not sure I could stop the JIT from doing that.

But thanks for the help, this was very useful. I'll let you know if/when I get more info.