Hacker News new | past | comments | ask | show | jobs | submit login
How Slow Is JavaScript Really? JavaScript vs. C++ (Data Struct. & Optimization) (youtube.com)
3 points by scanny on April 21, 2021 | hide | past | favorite | 1 comment



I felt really stupid when I wrote this yesterday, which you would NEVER do in C++:

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status === "fulfilled") {
                ....
            }
        }
    }
Like really? We want the processor to test for equality 9 times for "f", "u", "l", "f", "i", "l", "l", "e", "d"? Or is there some built-in optimization for this?

Or should I do this, which feels hacky, but reduces it to 1 equality test?

    const FULFILLED === "f";

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status[0] === FULFILLED) {
                ....
            }
        }
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: