Skip to content

cache의 data structure에 따른 성능 차이 #418

Discussion options

You must be logged in to vote

@highballplz 안녕하세요 하이볼님!
제 생각에는 두 함수의 로직에 차이가 있어보입니다.

위쪽 함수의 경우 if (cache.has(i)) return cache.get(i);를 사용하고
아래쪽 함수의 경우 if (cache[i]) return cache[i];를 사용하는데,

위의 경우 값이 0인 경우에도 해당 값을 재활용하지만, 아래의 경우에는 cache[i] = 0인 경우, false 처리되어 메모를 활용하지 못하고 다시 계산을 하게되는것으로 보입니다.
해당 내용 수정해서 테스트 결과 4~50ms정도로 유사하게 나오네요!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@highballplz
Comment options

highballplz Sep 4, 2024
Collaborator Author

Answer selected by highballplz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants