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 8229129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:41:45+00:00 2026-06-07T16:41:45+00:00

This answer on another question says that array.map(&:to_s) is faster than array.map { |n|

  • 0

This answer on another question says that

array.map(&:to_s)

is faster than

array.map { |n| n.to_s }

In the first example, & turns :to_s into a Proc. The second example uses a block.

Why might a Proc be faster than a block in that benchmark? Is there some optimization that this technique allows the interpreter to do?

  • 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-06-07T16:41:47+00:00Added an answer on June 7, 2026 at 4:41 pm

    As others have been said this is specifically about Symbol#to_proc rather than procs in general and it is almost certainly ruby implementation dependant. Before Symbol#to_proc was in ruby itself, the pure ruby implementations of it were definitely slower the the equivalent block.

    For a real answer you’d want to profile ruby while you’re executing such a benchmark.

    My reading of the ruby source code is that when you call Symbol#to_proc the proc you get is a bit special: The body of the proc is just a C api call (rb_funcall_passing_block), whereas in the other cases it’s actual ruby code which takes a little longer to execute.

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

Sidebar

Related Questions

So I saw an answer in another question saying that this should work: using
In a comment on this answer of another question , the commenter says: don’t
The answer to another SO question was to use this SQL query: SELECT o.Id,
This question is a result of what i noticed while trying to answer another
This question is an continuation on another StackOverflow post where no clear answer is
This is a bit esoteric, but maddening. In an answer to another question ,
I am testing an example snippet that I found as an answer on another
This is kind of a 'double' question that might have a single answer. I'm
[Note: There is another thread about this problem but it did not answer the
This answer says: Vim's undo/redo system is unbeatable. Type something, undo, type something else,

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.