Class: Graph::Function::IntsComparison
- Inherits:
-
Object
- Object
- Graph::Function::IntsComparison
- Extended by:
- PlotConfig, ReformatString
- Defined in:
- lib/graph/function/ints_comparison.rb
Class Method Summary collapse
Methods included from ReformatString
camel_title, escape_underscores
Methods included from PlotConfig
Class Method Details
.of(method_one, method_two) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/graph/function/ints_comparison.rb', line 7 def self.of(method_one, method_two) fail unless method_one.is_a?(Method) && method_two.is_a?(Method) Gnuplot.open do |gp| Gnuplot::Plot.new(gp) do |plot| self.class.send(:define_method, :a, proc(&method_one)) self.class.send(:define_method, :b, proc(&method_two)) plot.title (title = "#{camel_title(method_one.name)} vs #{camel_title(method_two.name)}") set_up(plot) x = Graph::Function.configuration.step pb = ProgressBar.create(title: title, total: x.size) y = x.collect do |v| pb.increment array = (0..v - 1).to_a.shuffle Benchmark.measure { a(array) }.real end plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" ds.title = "#{escape_underscores(method_one.name)}" end pb.reset z = x.collect do |v| pb.increment array = (0..v - 1).to_a.shuffle Benchmark.measure { b(array) }.real end plot.data << Gnuplot::DataSet.new( [x, z] ) do |ds| ds.with = "linespoints" ds.title = "#{escape_underscores(method_two.name)}" end end end end |