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

  • Home
  • SEARCH
  • 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 3333566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:48:40+00:00 2026-05-17T23:48:40+00:00

It started out when I read Guido van Rossum’s essay An Optimization Anecdote .

  • 0

It started out when I read Guido van Rossum’s essay An Optimization Anecdote.

Deciding to try the same thing in JavaScript, I timed the following:

numbers.map(function(x){ return String.fromCharCode(x); });

This was pretty fast already, but why not eliminate the anonymous function completely and pass String.fromCharCode directly to map():

numbers.map(String.fromCharCode);

I timed it and… …this was ~100 times slower than the previous version. How come?

Somehow passing this native function directly to Array.map() is way slower than wrapping it inside another function and passing that to Array.map().

  • It’s not browser specific: tested in Chrome, Firefox and Opera.

  • It’s not specific to map(): tried forEach(), which behaved similarly.

  • It’s not specific to built-in functions: tried Math.round() and Math.sin() – with these the results were as one would expect: passing the function to Array.map() directly was a little bit faster than using intermediate anonymous function.

It seems the problem is with String.fromCharCode specifically.

What’s going on here?

PS. Originally posed this question in Hacker News thread, but since the related article is about Python, I thought it would get more exposure to JavaScript devs when posted here. Sorry for cross-posting.

  • 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-17T23:48:40+00:00Added an answer on May 17, 2026 at 11:48 pm

    Found the solution by myself.

    The problem is that String.fromCharCode() takes multiple arguments and Array.map() also passes multiple arguments to the callback. Therefore the code:

    numbers.map(String.fromCharCode);
    

    Is actually equivalent of:

    numbers.map(function(x, y, z){ return String.fromCharCode(x, y, z); });
    

    From which it is quite apparent why it’s so slow. Additionally it’s buggy too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Back in the 90s when I first started out with MFC I used to
I've just started building a prototype application in Django. I started out by working
I'm getting started on figuring out how to use RESTful design. I have this
I started an application in Google App Engine right when it came out, to
I've just started learning Lisp and I can't figure out how to compile and
I have just started learning Erlang and am trying out some Project Euler problems
I started trying to play with Mono, mostly for fun at the moment. I
I started using subversion for one of my projects and it would be absolutely
I started a Rails project recently and decided to use RESTful controllers. I created
I started programming C# applications when the 1.0 framework was first released. I worked

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.