summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-10 10:37:24 -0600
committermo khan <mo.khan@gmail.com>2020-05-10 10:37:24 -0600
commitb2ea3e84a6ec775ceda0e64b1045085444755f06 (patch)
treeb9c9ebcc3e89f3b7fe949316e2473bf3c54b8d51 /bin
parent7099bcdb3f3b140495e8a742fa90da3bd04ffb4f (diff)
Identify and resolve bottleneck with csv parsing
Diffstat (limited to 'bin')
-rwxr-xr-xbin/csv-benchmark28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/csv-benchmark b/bin/csv-benchmark
new file mode 100755
index 0000000..f7573f2
--- /dev/null
+++ b/bin/csv-benchmark
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+
+require 'bundler/inline'
+
+gemfile do
+ source 'https://rubygems.org'
+
+ gem 'benchmark-ips', '~> 2.8'
+ gem 'fastcsv', '~> 0.0'
+ gem 'fastest-csv'
+end
+
+require 'benchmark/ips'
+require 'csv'
+require 'fastcsv'
+require 'fastest-csv'
+
+csv = "\"spandx\",\"0.0.0\",\"MIT\""
+
+Benchmark.ips do |x|
+ x.report("CSV.parse") { CSV.parse(csv)[0] }
+ x.report("csv.split") { csv.split(',', 3) }
+ x.report("csv.split-with-slice") { csv.chomp.split(',', 3).slice(1...-1) }
+ x.report("csv.regex") { csv.scan(/"(\S+)","*(\d+.\d+.\d+)","(\S+)"/)[0] }
+ x.report("csv.fastcsv") { FastCSV.raw_parse(csv) { |x| x } }
+ x.report("csv.fastestcsv") { FastestCSV.parse_line(csv) }
+ x.compare!
+end