Last active
June 11, 2020 14:27
-
-
Save hopsoft/ae361319c54bbcb4f8e2 to your computer and use it in GitHub Desktop.
Revisions
-
hopsoft revised this gist
Dec 26, 2015 . 1 changed file with 2 additions and 1 deletion.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 @@ -1,7 +1,8 @@ |strategy |time |degradation| |:------------------|-------:|----------:| |check for nil |0.040230| 1.00 | |check respond_to |0.101780| 2.529 | |rescue |2.103482|52.286 | |active_support try |0.151765| 3.772 | |safe navigation |0.040369| 1.003 | -
hopsoft revised this gist
Dec 26, 2015 . 1 changed file with 7 additions and 6 deletions.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 @@ -1,6 +1,7 @@ |strategy |time |degradation| ------------------------------------------ |check for nil |0.040230| 1.00 | |check respond_to |0.101780| 2.529 | |rescue |2.103482|52.286 | |active_support try |0.151765| 3.772 | |safe navigation |0.040369| 1.003 | -
hopsoft revised this gist
Dec 26, 2015 . 1 changed file with 6 additions and 0 deletions.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,6 @@ strategy |time |degradation check for nil |0.040230| 1.00 check respond_to |0.101780| 2.529 rescue |2.103482|52.286 active_support try |0.151765| 3.772 safe navigation |0.040369| 1.003 -
hopsoft renamed this gist
Dec 26, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hopsoft created this gist
Dec 26, 2015 .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,6 @@ user system total real check for nil: 0.040000 0.000000 0.040000 ( 0.040230) check respond_to: 0.100000 0.000000 0.100000 ( 0.101780) rescue: 2.080000 0.020000 2.100000 ( 2.103482) active_support try: 0.150000 0.000000 0.150000 ( 0.151765) safe navigation: 0.040000 0.000000 0.040000 ( 0.040369) 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,27 @@ require "benchmark" require "active_support/all" Benchmark.bm do |x| count = 1_000_000 label_size = 20 x.report "check for nil:".rjust(label_size) do count.times { nil && nil.length } end x.report "check respond_to:".rjust(label_size) do count.times { nil.length if nil.respond_to?(:length) } end x.report "rescue:".rjust(label_size) do count.times { nil.length rescue nil } end x.report "active_support try:".rjust(label_size) do count.times { nil.try(:length) } end x.report "safe navigation:".rjust(label_size) do count.times { nil&.length } end end