blob: d5d57d67f709fcbc64fe86ceba74c4fa60b2046d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/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
|