why does using a filter with a key for acess Element in a enum make it slower than using Object.values()? i thought acessing values by key would be faster
code (this code was code Typescript transpiled).
//test 1
var Partials;
(function (Partials) {
Partials[Partials["User"] = 0] = "User";
Partials[Partials["Channel"] = 1] = "Channel";
Partials[Partials["GuildMember"] = 2] = "GuildMember";
Partials[Partials["Message"] = 3] = "Message";
Partials[Partials["Reaction"] = 4] = "Reaction";
Partials[Partials["GuildScheduledEvent"] = 5] = "GuildScheduledEvent";
Partials[Partials["ThreadMember"] = 6] = "ThreadMember";
})(Partials || (Partials = {}));
Object.values(Partials).filter(e => typeof e !== 'string')
//test 2
var Partials;
(function (Partials) {
Partials[Partials["User"] = 0] = "User";
Partials[Partials["Channel"] = 1] = "Channel";
Partials[Partials["GuildMember"] = 2] = "GuildMember";
Partials[Partials["Message"] = 3] = "Message";
Partials[Partials["Reaction"] = 4] = "Reaction";
Partials[Partials["GuildScheduledEvent"] = 5] = "GuildScheduledEvent";
Partials[Partials["ThreadMember"] = 6] = "ThreadMember";
})(Partials || (Partials = {}));
Object.keys(Partials).filter(key => typeof Partials[key] === 'string')
i think using keys might be causing more recursion. For exemple, when i use Object.value(), i already receive the value in the param, so i just need to check type. but when i use keys, i have to search in array again using key, and check type. is that why Object.values() is faster in my code? i dont know, that's just what i think...
)