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.