#!/usr/bin/env ruby require 'bundler/setup' require 'flows' require 'benchmark/ips' require 'pry' require 'gli' require 'warning' require_relative 'benchmark_cli/helpers' require_relative 'benchmark_cli/examples' require_relative 'benchmark_cli/ruby' require_relative 'benchmark_cli/compare' Warning.ignore(/BigDecimal.new is deprecated/) # Benchmarking CLI application class BenchmarkCLI extend GLI::App extend Flows::Result::Helpers program_desc 'Benchmark runner' use_openstruct true desc 'Run Ruby benchmarks' ruby_benchmarks = Ruby::BENCHMARKS.keys.map(&:to_s) command :ruby do |cmd| cmd.flag( %i[b benchmarks], desc: "benchmarks to run. Pick from: #{ruby_benchmarks.join(', ')}. By default all the benchmarks are executed.", type: String, multiple: true, must_match: ruby_benchmarks, default_value: ruby_benchmarks ) cmd.action do |_gopts, opts, _args| result = Ruby::Command.new(opts.benchmarks).call case result when match_ok then puts 'Benchmark finished! Thank you for patience!' when match_err then exit_now!(result.error) end end end desc 'Compare different Flows abstractions and alternatives from the other libraries' command :compare do |cmd| benchmarks = Compare::BENCHMARKS.keys.map(&:to_s) cmd.flag %i[b benchmarks], desc: 'benchmarks to run', type: String, multiple: true, must_match: benchmarks, default_value: benchmarks implementations = Compare::IMPLEMENTATIONS.keys.map(&:to_s) cmd.flag %i[i implementations], desc: 'implementations to compare', type: String, multiple: true, must_match: implementations, default_value: implementations cmd.action do |_gopts, opts, _args| result = Compare::Command.new(opts.benchmarks, opts.implementations).call case result when match_ok then puts 'Benchmark finished! Thank you for patience!' when match_err then exit_now!(result.error) end end end end exit BenchmarkCLI.run(ARGV)