Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1015649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:25:56+00:00 2026-05-16T10:25:56+00:00

Has anybody done benchmarking, or can link to an article on this subject? Particularly

  • 0

Has anybody done benchmarking, or can link to an article on this subject? Particularly interested in IE results, since usually JS performance is not a problem in other browsers.

I would like to know how much slower it is to do something like:

var numbers = [1, 2, 3, 4, 5, 6, 7];
var results = numbers.map(function() { 
  // do some stuff
});

instead of the typical:

var numbers = [1, 2, 3, 4, 5, 6, 7];
var results = [];

for (var i = 0; i < numbers.length; i++) {
  var number = numbers[i];
  var result;
  // do some stuff
  results.push(result);
}

I obviously prefer the functional style, but I assume the extra overhead of calling an extra function for each item could slow things down with big collections.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:25:57+00:00Added an answer on May 16, 2026 at 10:25 am

    Not content with the lack of proof on this subject, I wrote a short benchmark. It’s far from perfect but I think it answers the question.

    I ran it in IE 8/win, and while the functional method is slower, it’s never going to be the bottleneck in real code. (Unless you’re doing stuff that you shouldn’t be doing in the client anyway)

    So I will be using the cleaner approach whenever I have to pick (yay)

    (Best of 5)
    Functional method: 453ms
    Old school approach: 156ms

    Array.prototype.map = function(fun) {
      var len = this.length >>> 0;
      if (typeof fun != "function")
        throw new TypeError();
    
      var res = new Array(len);
      var thisp = arguments[1];
      for (var i = 0; i < len; i++) {
        if (i in this)
          res[i] = fun.call(thisp, this[i], i, this);
      }
    
      return res;
    };
    
    /**
     *
     *
     */
    
    // Initialize test array
    var numbers = [];
    for (var i = 0; i < 100000; i++) numbers.push(i);
    
    // Benchmark!
    var start = +new Date();
    
    // Test 1
    var results1 = numbers.map(function(num) {
      return num + num;
    });
    
    alert('1. Functional map:' + (start - new Date()));
    start = +new Date();
    
    // Test 2
    var results2 = [];
    for (var j = 0, l = numbers.length; j < l; j++) {
      var num = numbers[j];
      results2.push(num + num)
    }
    
    alert('1. Old school approach' + (start - new Date()));
    start = +new Date();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anybody done any benchmarking/evaluation of the popular open-source embedded SQL DBs for performance,
This seems to be a big gap in it's spring integration. Has anybody done
has anybody done anything with scripts to parse an incoming e mail to a
Has anybody done anything like that? I need to import 3d objects, done in
I've searched but was unable to find an existing regex function. Has anybody done
Has anybody used Eclipse memory manager to detect memory leak in java codes? Can
Has anybody compared SimpleDB and Tokyo Cabinet for performance and scalability? I'm coding my
Has anybody done a comparison of the overhead of the various background processing techniques?
Has anybody ever successfully written code to extract data from a SharePoint 2007 list
Has anybody written a plugin for outlook web access? Are there any resources to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.