Last active
May 13, 2023 12:17
-
-
Save maxim/58105aa34f18b64cd2583fe1c857c060 to your computer and use it in GitHub Desktop.
Revisions
-
maxim revised this gist
May 13, 2023 . 1 changed file with 15 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 @@ -16,4 +16,18 @@ } x.compare! end # Warming up -------------------------------------- # catch a throw 347.786k i/100ms # rescue and exception 135.262k i/100ms # return string 795.463k i/100ms # Calculating ------------------------------------- # catch a throw 3.465M (± 0.4%) i/s - 17.389M in 5.019335s # rescue and exception 1.359M (± 2.0%) i/s - 6.898M in 5.077732s # return string 7.949M (± 0.4%) i/s - 39.773M in 5.003773s # Comparison: # return string: 7948778.8 i/s # catch a throw: 3464519.8 i/s - 2.29x slower # rescue and exception: 1359120.9 i/s - 5.85x slower -
maxim revised this gist
May 13, 2023 . 1 changed file with 7 additions and 22 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,34 +1,19 @@ code1 = -> { catch(:foo) { throw(:foo, 'string') } } code2 = -> { begin; raise RuntimeError; rescue RuntimeError; 'string' end } code3 = -> { 'string' } Benchmark.ips do |x| x.report("catch a throw") { value = code1.call } x.report("rescue and exception") { value = code2.call } x.report("return string") { value = code3.call } x.compare! end -
maxim revised this gist
May 13, 2023 . No changes.There are no files selected for viewing
-
maxim revised this gist
May 13, 2023 . 1 changed file with 2 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 @@ -1,3 +1,5 @@ # THIS BENCH TURNED OUT INVALID. SEE GIST COMMENT. Benchmark.ips do |x| code = -> { catch(:foo) { throw(:foo, 'string') } } x.report("catch a throw") { -
maxim revised this gist
May 10, 2023 . No changes.There are no files selected for viewing
-
maxim revised this gist
May 10, 2023 . 1 changed file with 10 additions and 10 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 @@ -9,7 +9,7 @@ value = code.call } code = -> { 'string' } x.report("return string") { value = code.call } @@ -18,15 +18,15 @@ end # Warming up -------------------------------------- # catch a throw 800.000k i/100ms # rescue and exception 806.001k i/100ms # return string 808.500k i/100ms # Calculating ------------------------------------- # catch a throw 8.056M (± 0.4%) i/s - 40.800M in 5.064886s # rescue and exception 8.037M (± 0.4%) i/s - 40.300M in 5.014526s # return string 8.017M (± 2.4%) i/s - 40.425M in 5.045557s # Comparison: # catch a throw: 8055618.1 i/s # rescue and exception: 8036783.6 i/s - same-ish: difference falls within error # return string: 8017444.4 i/s - same-ish: difference falls within error -
maxim created this gist
May 10, 2023 .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,32 @@ Benchmark.ips do |x| code = -> { catch(:foo) { throw(:foo, 'string') } } x.report("catch a throw") { value = code.call } code = -> { begin; raise RuntimeError; rescue RuntimeError; 'string' end } x.report("rescue and exception") { value = code.call } code = -> { "string" } x.report("return string") { value = code.call } x.compare! end # Warming up -------------------------------------- # catch a throw 809.111k i/100ms # rescue and exception 809.739k i/100ms # return string 807.068k i/100ms # Calculating ------------------------------------- # catch a throw 8.048M (± 0.8%) i/s - 40.456M in 5.027045s # rescue and exception 8.050M (± 0.8%) i/s - 40.487M in 5.029488s # return string 8.040M (± 0.4%) i/s - 40.353M in 5.018972s # Comparison: # rescue and exception: 8050433.0 i/s # catch a throw: 8048082.4 i/s - same-ish: difference falls within error # return string: 8040326.6 i/s - same-ish: difference falls within error