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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:51:43+00:00 2026-05-22T00:51:43+00:00

I want to load an array with 1million guids, then loop through them and

  • 0

I want to load an array with 1million guids, then loop through them and perform some string operations on each element of the array.

I only want to benchmark the time for the operations I perform on each element of the array, not the time it takes to initialize the array with 1 million rows.

I tried doing a benchmark before, but I didn’t understand the output.

How would you do this, I have:

rows = []
(1..1000000).each do |x|
    rows[x] = // some string data
end

n = 50000
Benchmark.bm do |x|

      rows.each do |r|
          # perform string logic here
      end

end

Will this return consistent results?
Any guidance/gotcha’s I should know about?

  • 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-22T00:51:43+00:00Added an answer on May 22, 2026 at 12:51 am

    Yes, this will return consistent results. You need to report the benchmark, however and (if processing a million rows is too fast) you will need to use your n variable to iterate a few times. (Start with a low n and increase it if your times are in the tenth or hundredths of a second).

    require 'benchmark'
    # Prepare your test data here
    n = 1
    Benchmark.bm do |x|
      x.report('technique 1') do
        n.times do
          # perform your string logic here
        end
      end
      x.report('technique 2') do
        n.times do
          # perform your alternative logic here
        end
      end
    end
    

    Make sure you run your multiple comparisons in the same Benchmark block; don’t write one attempt, write down the numbers, and then change the code to run it again. Not only is that more work for you, but it also may produce incorrect comparisons if your machine is in a different state (or if, heaven forfend, you run one test on one machine and another test on another machine).

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

Sidebar

Related Questions

I have some uiButtons in my table view and i want to load them
i have a array with data,i want to load the dictiionary type element with
I have a combo box that I want to load with a string array
I have a class - XClass, that I want to load into an array
I want to load some images into my application from the file system. There's
I want to load some data from mysql into my cocoa application view before
I want to load some helper in a model. How to do this? Tried
I want to load data (an array of strings) from the parent view into
I want to load an image from an array and set the view to
I want to load a txt file into an array like file() does in

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.