C VS C++ execution time with the same algorithm


  • 1
    F

    Same algorithm using classical loop
    on C it takes 1ms for executing
    on C++ it takes 10ms
    Just wondering, why C++ takes 10 times executing time than C....

    lots other solutions are amazing, but less maintainable code..

    int hammingWeight(uint32_t n) {

      int count = 0;
        for (int i = 32; i > 0; --i) {
             if (n << 31 ^ 0 > 0) {
                 ++count;
             }
             
             n = n >> 1;
        }
        
        return count;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.