Last active
November 30, 2016 00:28
-
-
Save guilhermesimoes/148cd905a99289441e5c46c991daa469 to your computer and use it in GitHub Desktop.
Revisions
-
guilhermesimoes created this gist
Nov 25, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # gem install benchmark-ips require "benchmark/ips" uri = "http://twitter.com/user/statuses/1234567891011121314" Benchmark.ips do |x| x.report("file.basename") { File.basename(uri) } x.report("split('/').last") { uri.split("/").last } x.report("split('/')[-1]") { uri.split("/")[-1] } x.compare! end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ Warming up -------------------------------------- file.basename 68.360k i/100ms split('/').last 37.097k i/100ms split('/')[-1] 44.238k i/100ms Calculating ------------------------------------- file.basename 863.262k (±12.9%) i/s - 4.238M in 5.006200s split('/').last 603.615k (± 9.0%) i/s - 3.005M in 5.027355s split('/')[-1] 572.872k (± 9.7%) i/s - 2.875M in 5.070618s Comparison: file.basename: 863262.4 i/s split('/').last: 603615.0 i/s - 1.43x slower split('/')[-1]: 572872.0 i/s - 1.51x slower