main
 1#!/usr/bin/env ruby
 2# frozen_string_literal: true
 3
 4require 'bundler/inline'
 5
 6gemfile do
 7  source 'https://rubygems.org'
 8
 9  gem 'benchmark-ips', '~> 2.8'
10  gem 'fastcsv', '~> 0.0'
11  gem 'fastest-csv'
12  gem 'spandx', path: '.'
13end
14
15require 'benchmark/ips'
16require 'csv'
17require 'fastcsv'
18require 'fastest-csv'
19require 'spandx'
20
21csv = '"spandx","0.0.0","MIT"'
22
23Benchmark.ips do |x|
24  x.report('csv') { CSV.parse(csv)[0] }
25  x.report('fastcsv') { FastCSV.raw_parse(csv) { |y| y } }
26  x.report('fastest-csv') { FastestCSV.parse_line(csv) }
27  x.report('regex') { csv.scan(/"(\S+)","*(\d+.\d+.\d+)","(\S+)"/)[0] }
28  x.report('spandx') { Spandx::Core::CsvParser.parse(csv) }
29  x.report('split') { csv.split(',', 3) }
30  x.report('split-with-slice') { csv.chomp.split(',', 3).slice(1...-1) }
31  x.compare!
32end