Comments (2)
요거요거 어디서 본 말인데 이게 맞는듯 합니다.
from febase.
결론부터 말하면, 별 차이 없고 if 문의 성능이 조금 더 나은 듯 하다.
코드 라인 수가 적다고 컴파일 시간이 항상 더 빠른 것은 아니다. 삼항연산자를 쓰는 이유는 코드의 가독성을 좀 더 높이기 위함이며, 성능을 최적화 하고 싶다면 삼항연산자를 쓸지 if 문을 쓸지 고민하는 것보다 다른 부분을 리팩토링 하는 것이 훨씬 더 효율적이다.
let start = (new Date()).getTime();
let flag = false;
for(let i = 0; i < 100000000; i++) {
let tmp = null;
tmp = flag ? true : false;
}
let end = (new Date()).getTime();
console.log('ternary op.', end-start); // 매번 조금씩 다르긴 하지만 일반적으로 84~87
start = (new Date()).getTime();
for(let i = 0; i < 100000000; i++) {
let tmp = null;
if(flag) tmp = true;
else tmp = false;
}
end = (new Date()).getTime();
console.log('if state.', end-start); // 매번 조금씩 다르긴 하지만 일반적으로 79~81
from febase.
Related Issues (17)
- 2021년 Febase 스터디 방향성 HOT 7
- Static method, Instance method
- 안녕하세요.
- 호이스팅 HOT 1
- 이벤트 위임에 대한 고찰 HOT 2
- 이벤트 위임에서 하위 엘리먼트를 어떻게 구분하지?
- 최성흠 추가 조사 후 PR 보내기
- Hard Binding의 예제에 대해서 한번 더 설명. HOT 2
- undefined의 진짜 의미 HOT 1
- js for-loop의 종류와 사용 위치
- HTTP Request 최적화
- 그래픽 요소 최적화
- lazy loading
- 차트 라이브러리
- Http통신, Socket 통신
- [코드 스플리팅] 컴포넌트 lazy 로딩 시 캐싱은 어떻게 하는지
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from febase.