utilForever / Cubby-v1

Voxel-based game client (based on AlwayGeeky's Vox)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

item source

rinechran opened this issue · comments

아이템 소스를 볼떄 느끼는건데..
std::string GetEquipmentTitleForType(EquipmentType type)
{
switch (type)
{
// Weapons
case EquipmentType::None: { return ""; }
case EquipmentType::NormalPickaxe: { return "Normal Pickaxe"; }
case EquipmentType::Torch: { return "Torch"; }
case EquipmentType::Hammer: { return "Hammer"; }
case EquipmentType::MageStaff: { return "Mage Staff"; }
case EquipmentType::NecroStaff: { return "Necro Staff"; }
case EquipmentType::PriestStaff: { return "Priest Staff"; }
case EquipmentType::DruidStaff: { return "Druid Staff"; }
case EquipmentType::TwoHandedSword: { return "Two Handed Sword"; }
case EquipmentType::Boomerang: { return "Boomerang"; }
case EquipmentType::Bomb: { return "Bomb"; }
case EquipmentType::KnifeLeft: { return "Knife"; }
case EquipmentType::KnifeRight: { return "Knife"; }
case EquipmentType::FireballHandLeft: { return "Fireball Hands"; }
case EquipmentType::FireballHandRight: { return "Fireball Hands"; }
case EquipmentType::Mace: { return "Mace"; }
case EquipmentType::Sickle: { return "Sickle"; }
case EquipmentType::DragonBow: { return "Dragon Bow"; }

이런식의 코딩보다..
좀 귀잖기는 하겠지만..

std::unordered_map<EquipmentType, std::string> temp{
{EquipmentType::None,""},

}

이렇게 하는게 속도면으로 더 이득을볼수있지않을까요...음..

좀 궁금하네요..

아뇨. 이미 enum 화된 값을 단순히 cmp로 비교하는것이기때문에 당연히 헤쉬된 값보다 빠릅니다.

그런가요?
전 당연히 해쉬랑 비교를 하면 빅오1이라고 생각을해서..
아이템수가 많을시는 .. 어떻게 될지.. case가 n만큼..비교를 하니.

cmp로 비교하는 시간보다 값을 해쉬해서 찾는 찾아가는 시간이 더 깁니다... 값이 크지 않는한.
한번 테스트해보시면 좋겠네요.

만약에 커진다고 해도 그것으로 보는 이득보다 손해가 훨씬 더 많습니다... 리소스라던지.

어셈블리에서 제일 시간을 많이 잡아먹는게 jmp 또는 call 입니다.
이미 비교 함수로 call 한 시점부터 아웃입니다...

만약에 이게 list라면 당연히 map이 훨씬 빠르겟죠.
이터레이터를 loop문 즉 jmp로 돌리게되니까. 그러니까 느린겁니다.

더 빨리 접근한다고 하면 차라리 const std::string Types[] = { Enum 번호에 따른 정의. } 이후
Types[Enum Value] 로 접근하는게 훨씬 빠를겁니다..

아하 감사합니다