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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:13:27+00:00 2026-06-15T05:13:27+00:00

I have an array of ~10,000 strings and integers that I want to serialize

  • 0

I have an array of ~10,000 strings and integers that I want to serialize into a Rails web page. The eventual goal is to get the array into a JavaScript array, but I’m happy to just have it as a text blob that I then parse client side.

I can’t cache the string, the values change every request.

This takes ~25ms on my VPS:

arr = ["ABCD", 1] * 10000 # always in string, number, string, number order
start = Time.now
arr.to_s
duration = (Time.now - start)*1000
puts "took #{duration}ms"

Can we do better?

edit

@sawa’s answer is correct, to_json is fast and a good way to do this. I was getting thrown off because to_json in a Rails environment is overridden. Use JSON.generate(arr) instead.

  • 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-15T05:13:29+00:00Added an answer on June 15, 2026 at 5:13 am

    JSON is faster as the array gets longer. As I tested with ["ABCD", 1] * n, when approx n < 50, to_s is faster, but when n > 50, to_json is faster.

    arr = ["ABCD", 1] * 10000 # always in string, number, string, number order
    
    start = Time.now
    arr.to_s
    duration = (Time.now - start)*1000
    puts "took #{duration}ms"
    
    require "json"
    start = Time.now
    arr.to_json
    duration = (Time.now - start)*1000
    puts "took #{duration}ms"
    
    # =>
    # took 7.546628ms # to_s
    # took 4.684186ms # to_json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have numpy array of 1,000 elements which I want to convert to strings.
I have large number of strings, approximately 15,000 that I stored in a SQLite
I'm using action script and I have an array with more than 400.000 strings
I have integers under the value of 255 and want to save them into
if I have a large javascript string array that has over 10,000 elements, how
I have a pList of strings which I'm bundling into an NSMutable Array. NSString
Let's say I have an array, @theArr, which holds 1,000 or so elements such
I have a byte array of around 10,000 bytes which is basically a blob
I have array of strings, String[] data and it's 10 elements has value P
I want to write a method that when supplied an array of ints will

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.