0
+# A gem that provides a nice DSL for a common type of benchmark.
0
-A plugin for the Merb framework that provides ....
0
+ Benchmark.warmer(TIMES) do # [1]
0
+ columns :one, :two, :three # [2]
0
+ titles :one => "Option 1", :three => "Option 3" # [3]
0
+ group("Squeezing") do # [4]
0
+ report "with #squeeze" do # [5]
0
+ one { "abc//def//ghi//jkl".squeeze("/") } # [6]
0
+ two { "abc///def///ghi///jkl".squeeze("/") }
0
+ three { "abc////def////ghi////jkl".squeeze("/") }
0
+ report "with #gsub" do
0
+ one { "abc//def//ghi//jkl".gsub(/\/+/, "/") }
0
+ two { "abc///def///ghi///jkl".gsub(/\/+/, "/") }
0
+ three { "abc////def////ghi////jkl".gsub(/\/+/, "/") }
0
+ report "with #split" do
0
+ one { "aaa/aaa/aaa.bbb.ccc.ddd".split(".") }
0
+ two { "aaa//aaa//aaa.bbb.ccc.ddd.eee".split(".") }
0
+ three { "aaa///aaa///aaa.bbb.ccc.ddd.eee.fff".split(".") }
0
+ report "with #match" do
0
+ one { "aaa/aaa/aaa.bbb.ccc.ddd".match(/\.([^\.]*)$/) }
0
+ two { "aaa//aaa//aaa.bbb.ccc.ddd.eee".match(/\.([^\.]*)$/) }
0
+ three { "aaa///aaa///aaa.bbb.ccc.ddd.eee.fff".match(/\.([^\.]*)$/) }
0
+ # [1] Specify the number of times you want to run each benchmark
0
+ # [2] Specify the column names. By default, they will be displayed as upcased
0
+ # versions of themselves.
0
+ # [3] Specify prettier titles via a Hash. You do *not* need to specify the
0
+ # same column in both columns and titles.
0
+ # [4] Specify a group of benchmarks you wish to run
0
+ # [5] Specify the name of the report you wish to run
0
+ # [6] Optionally, specify several different variants of the benchmark. This could
0
+ # be useful if you're testing a new alorithm, and wish to compare a bunch of
0
+ # benchmarks against each algorithms. In most cases, you will probably want to
0
+ # use the variant below, which does not require columns.
0
+ # Running the benchmarks 100000 times each...
0
+ # Option 1 | TWO | Option 3 |
0
+ # -----------------------------------------------------
0
+ # Squeezing with #squeeze 0.15 | 0.15 | 0.14 |
0
+ # with #gsub 0.38 | 0.35 | 0.36 |
0
+ # -----------------------------------------------------
0
+ # Spliting with #split 0.43 | 0.51 | 0.61 |
0
+ # with #match 0.29 | 0.35 | 0.38 |
0
+ # -----------------------------------------------------
0
+ Benchmark.warmer(TIMES) do
0
+ report "with #squeeze" do
0
+ "abc//def//ghi//jkl".squeeze("/")
0
+ report "with #gsub" do
0
+ "abc//def//ghi//jkl".gsub(/\/+/, "/")
0
+ report "with #split" do
0
+ "aaa/aaa/aaa.bbb.ccc.ddd".split(".")
0
+ report "with #match" do
0
+ "aaa/aaa/aaa.bbb.ccc.ddd".match(/\.([^\.]*)$/)
0
+ # ---------------------------------
0
+ # Squeezing with #squeeze 0.15 |
0
+ # ---------------------------------
0
+ # Spliting with #split 0.43 |
0
+ # ---------------------------------
0
\ No newline at end of file
Comments
No one has commented yet.