bin/benchmark
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/setup'
require 'honey_format'
require 'benchmark/ips'
require 'csv'
require 'honey_format/cli/benchmark_cli'
cli = HoneyFormat::BenchmarkCLI.new
Writer = cli.writer
options = cli.options
input_path = options[:input_path]
benchmark_time = options[:benchmark_time]
benchmark_warmup = options[:benchmark_warmup]
lines_multipliers = options[:lines_multipliers]
original_csv = input_path ? File.read(input_path) : cli.fetch_default_benchmark_csv
original_csv_lines = original_csv.lines
runtime_seconds = cli.expected_runtime_seconds(report_count: 3)
Writer.puts "Expected runtime: ~#{runtime_seconds} seconds.", verbose: true
lines_multipliers.each_with_index do |lines_multiplier, index|
rows = original_csv_lines[1..-1] * lines_multiplier
csv = original_csv_lines.first + rows.join
line_count = csv.lines.length
Writer.puts "== Benchmark #{index + 1} of #{lines_multipliers.length} =="
Writer.puts "path #{cli.used_input_path}"
Writer.puts "lines #{line_count}"
Writer.puts "multiplier #{lines_multiplier}"
Benchmark.ips do |x|
x.time = benchmark_time
x.warmup = benchmark_warmup
x.report('CSV no options') { CSV.parse(csv) }
x.report('CSV with header') { CSV.parse(csv, headers: true) }
x.report('HoneyFormat::CSV') { HoneyFormat::CSV.new(csv).rows }
x.compare!
end
end