File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -969,17 +969,17 @@ Note that this can only be used for removing characters from the end of a string
969969
970970```
971971$ ruby -v code/string/sub-vs-chomp.rb
972- ruby 2.2.2p95 (2015-04-13 revision 50295 ) [x86_64-darwin13]
972+ ruby 2.2.3p173 (2015-08-18 revision 51636 ) [x86_64-darwin13]
973973Calculating -------------------------------------
974- String#sub/regexp/ 38.068k i/100ms
975- String#chomp'string' 78.284k i/100ms
974+ String#sub/regexp/ 42.816k i/100ms
975+ String#chomp'string' 94.851k i/100ms
976976-------------------------------------------------
977- String#sub/regexp/ 560.625k (±17.1 %) i/s - 2.703M
978- String#chomp'string' 2.704M (±18.6 %) i/s - 12.839M
977+ String#sub/regexp/ 660.509k (± 8.0 %) i/s - 3.297M
978+ String#chomp'string' 2.803M (± 8.0 %) i/s - 13.943M
979979
980980Comparison:
981- String#chomp'string': 2703881.6 i/s
982- String#sub/regexp/: 560625.4 i/s - 4.82x slower
981+ String#chomp'string': 2803443.5 i/s
982+ String#sub/regexp/: 660508.7 i/s - 4.24x slower
983983```
984984
985985##### ` attr_accessor ` vs ` getter and setter ` [ code] ( code/general/attr-accessor-vs-getter-and-setter.rb )
Original file line number Diff line number Diff line change 33SLUG = 'YourSubclassType'
44
55def slow
6- SLUG . sub ( /Type$ / , '' )
6+ SLUG . sub ( /Type\z / , '' )
77end
88
99def fast
You can’t perform that action at this time.
0 commit comments