Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created September 20, 2013 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelmekki/6f5fcc120e052a84ffdd to your computer and use it in GitHub Desktop.
Save oelmekki/6f5fcc120e052a84ffdd to your computer and use it in GitHub Desktop.
> def test_inject(n)
> t1 = Time.now
> n.times do
> (0..n).inject(""){ |html, i| html + i.to_s }
> end
>
> Time.now - t1
> end
=> nil
>
> def test_map(n)
> t1 = Time.now
> n.times do
> (0..n).map{ |i|i.to_s }.join( '' )
> end
>
> Time.now - t1
> end
=> nil
> test_inject(1000)
=> 0.725195012
> test_map(1000)
=> 0.270933516
> test_inject(1000)
=> 0.721010102
> test_map(1000)
=> 0.262328001
> test_inject(1000)
=> 0.704366079
> test_map(1000)
=> 0.265108258
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment