The int from enum performance drama

If you really want to know what to avoid, you should look at the assembly, rather than start making up rules for yourself based on incomplete knowledge.

5 Likes

Because these little types allowed it in my program I changed the declaration to u8:

pub const CastleType = enum(u8) {
    short,
    long,

    pub fn u(self: CastleType) u8 {
        return @intFromEnum(self);
    }
}

and performance was for 99-100% again.

5 Likes

True. My knowledge is very limited, unfortunately.

what a great motivation you have to learn! a project that needs more knowledge!

3 Likes

That is true, on the other hand: inspecting asm to check if a compiler did its job is not my favorite hobby.

It’s not your favourite hobby yet :3

11 Likes