Results 1 to 5 of 5

Thread: node.js weirdness

  1. #1
    Join Date
    May 2007
    Posts
    526
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default node.js weirdness

    This is weird. At least with node.js v4, consider the following two programs:

    Program #1 :

    Code:
    'use strict';
    
    function f(x, y) {
        /*
    
         Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed posuere interdum sem. Quisque ligula eros ullamcorper
         quis, lacinia quis facilisis sed sapien. Mauris varius diam vitae arcu. Sed arcu lectus auctor vitae, consectetuer et
         venenatis eget velit. Sed augue orci, lacinia eu tincidunt et eleifend nec lacus. Donec ultricies nisl ut felis,
         suspendisse potenti. Lorem ipsum ligula ut hendrerit mollis, ipsum erat vehicula risus, eu suscipit sem libero nec
         erat. Aliquam volutpat. Sed congue augue vitae neque. Nulla consectetuer pede. Fusce purus morbi tortor magna
         condimentum vel, placerat id blandit sit amet tortor.
    
         */
    
        return (x + y);
    }
    
    for (let i = 0; i < 1000000000; i++) {
        if (f(i, i++) < 5) {
            //
        }
    }
    Program #2 :

    Code:
    'use strict';
    
    function f(x, y) {
        /*
    
         Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed posuere interdum sem. Quisque ligula eros ullamcorper
         quis, lacinia quis facilisis sed sapien. Mauris varius diam vitae arcu. Sed arcu lectus auctor vitae, consectetuer et
         venenatis eget velit. Sed augue orci, lacinia eu tincidunt et eleifend nec lacus. Donec ultricies nisl ut felis,
         erat. Aliquam volutpat. Sed congue augue vitae neque. Nulla consectetuer pede. Fusce purus morbi tortor magna
         condimentum vel, placerat id blandit sit amet tortor.
    
         */
    
        return (x + y);
    }
    
    for (let i = 0; i < 1000000000; i++) {
        if (f(i, i++) < 5) {
            //
        }
    }
    Now when ran and timed, here's the results for program #1 :

    Code:
    real    0m4.795s
    user    0m4.732s
    sys     0m0.012s
    and program #2 :

    Code:
    real    0m1.999s
    user    0m1.969s
    sys     0m0.016s
    Can you spot the difference and why the second program is twice as fast as the first one?

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    The comment actually affects runtime?

  3. #3
    Join Date
    May 2007
    Posts
    526
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Yup! For some reason, if the contents of the function exceeds 600 characters (including comments!), the function is not inlined. Sounds like a bug to me..

  4. #4
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    What version of 4 are you on?

  5. #5
    Join Date
    May 2007
    Posts
    526
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by tls View Post
    What version of 4 are you on?
    Our production server runs with 4.1.1.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •