-
-
Save oelmekki/6f5fcc120e052a84ffdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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