#!/usr/bin/env ruby # frozen_string_literal: true require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'benchmark-ips', '~> 2.8' gem 'fastcsv', '~> 0.0' gem 'fastest-csv' gem 'spandx', path: '.' end require 'benchmark/ips' require 'csv' require 'fastcsv' require 'fastest-csv' require 'spandx' csv = '"spandx","0.0.0","MIT"' Benchmark.ips do |x| x.report('csv') { CSV.parse(csv)[0] } x.report('fastcsv') { FastCSV.raw_parse(csv) { |y| y } } x.report('fastest-csv') { FastestCSV.parse_line(csv) } x.report('regex') { csv.scan(/"(\S+)","*(\d+.\d+.\d+)","(\S+)"/)[0] } x.report('spandx') { Spandx::Core::CsvParser.parse(csv) } x.report('split') { csv.split(',', 3) } x.report('split-with-slice') { csv.chomp.split(',', 3).slice(1...-1) } x.compare! end