Giter Club home page Giter Club logo

Comments (2)

samslow avatar samslow commented on June 28, 2024 1

요거요거 어디서 본 말인데 이게 맞는듯 합니다.

from febase.

dev-owen avatar dev-owen commented on June 28, 2024

결론부터 말하면, 별 차이 없고 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.