Last active
March 12, 2020 11:49
-
-
Save TeWu/c5e47eda22c6c7cd6ee63d818f941d99 to your computer and use it in GitHub Desktop.
Revisions
-
TeWu revised this gist
Mar 12, 2020 . 1 changed file with 4 additions and 3 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,5 +1,6 @@ require 'benchmark/ips' def fast(a, b) a > b ? a : b end @@ -8,6 +9,7 @@ def slow(a, b) [a, b].max end class GCSuite def warming(*) run_gc @@ -29,10 +31,9 @@ def run_gc end end Benchmark.ips do |x| x.config(time: 10, warmup: 2, suite: GCSuite.new) x.stats = :bootstrap x.confidence = 95 @@ -51,4 +52,4 @@ def run_gc end end x.compare! end -
TeWu created this gist
Mar 12, 2020 .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,54 @@ require 'benchmark/ips' def fast(a, b) a > b ? a : b end def slow(a, b) [a, b].max end class GCSuite def warming(*) run_gc end def running(*) run_gc end def warmup_stats(*); end def add_report(*); end private def run_gc GC.enable GC.start GC.disable end end suite = GCSuite.new Benchmark.ips do |x| x.config(:time => 10, :warmup => 2, :suite => suite) x.stats = :bootstrap x.confidence = 95 x.report('fast code') do |times| i = 0 while i < times fast(100, 200) i += 1 end end x.report('slow code') do |times| i = 0 while i < times slow(100, 200) i += 1 end end x.compare! end