Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@muddydixon

ExceptionのcatchでPromiseとtry-catchを比較する

More than 5 years have passed since last update.

ExceptioncatchPromiseを使った場合とtry-catchを使った場合の比較を雑にしました。

検証コード

% node
> console.time("promise"); i = 10000; while(i-- > 0){ new Promise((resolve, reject)=>{ throw new Error(); }).catch((err)=>{1}) } console.timeEnd("promise");
1: 139.171ms
undefined
> console.time("try"); i = 10000; while(i-- > 0){ try{ throw new Error(); }catch(err){ 1; } } console.timeEnd("try");
1: 56.821ms
undefined
> 

うん、使えるところなら try-catch 使おう。

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
muddydixon
JavaScript (HTML5, Node, jQuery) Perl R Hadoop MongoDB DataMining MachineLearning InfoGraphics
tver-technologies
Innovate TVision, Designing Value / テレビ・動画配信の可能性を切り拓き、新しい価値をデザインしていきます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?