Sha256: 3a5afb00e428f20b99b058c3a6b0c1d83d9d9d61f2b42d48c409cebfeff0da5e

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

#!/usr/bin/env ruby

require 'dentaku'
require 'allocation_stats'
require 'benchmark'

puts "Dentaku version #{Dentaku::VERSION}"
puts "Ruby version #{RUBY_VERSION}"

with_duplicate_variables = [
  "R1+R2+R3+R4+R5+R6",
  {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0, "r1"=>100000, "r2"=>0, "r3"=>200000, "r4"=>0, "r5"=>500000, "r6"=>0}
]

without_duplicate_variables = [
  "R1+R2+R3+R4+R5+R6",
  {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0}
]

def test(args, custom_function: true)
  calls = [ args ] * 100

  10.times do |i|

    stats = nil
    bm = Benchmark.measure do
      stats = AllocationStats.trace do

        calls.each do |formule, bound|

          calculator = Dentaku::Calculator.new

          if custom_function
            calculator.add_function(
              name:      :sum,
              type:      :numeric,
              signature: [:arguments],
              body:      ->(numbers) { numbers.inject(:+) },
            )
          end

          calculator.evaluate(formule, bound)
        end
      end
    end

    puts "  run #{i}: #{bm.total}"
    puts stats.allocations(alias_paths: true).group_by(:sourcefile, :class).to_text
  end
end

case ARGV[0]
when '1'
  puts "with duplicate (downcased) variables, with a custom function:"
  test(with_duplicate_variables, custom_function: true)

when '2'
  puts "with duplicate (downcased) variables, without a custom function:"
  test(with_duplicate_variables, custom_function: false)

when '3'
  puts "without duplicate (downcased) variables, with a custom function:"
  test(without_duplicate_variables, custom_function: true)

when '4'
  puts "with duplicate (downcased) variables, without a custom function:"
  test(without_duplicate_variables, custom_function: false)

else
  puts "select a run option (1-4)"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dentaku-2.0.1 spec/benchmark.rb
dentaku-2.0.0 spec/benchmark.rb
dentaku-1.2.6 spec/benchmark.rb
dentaku-1.2.5 spec/benchmark.rb