Skip to content

Instantly share code, notes, and snippets.

@pvijayfullstack
Forked from randym/benchmark.rb
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvijayfullstack/e9a21394e15ad5166587 to your computer and use it in GitHub Desktop.
Save pvijayfullstack/e9a21394e15ad5166587 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -s
# -*- coding: utf-8 -*-
$:.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'
require 'csv'
require 'benchmark'
row = []
input = (32..126).to_a.pack('U*').chars.to_a
20.times { row << input.shuffle.join}
times = 40000
Benchmark.bm(100) do |x|
# No Autowidth
x.report('axlsx_noautowidth') {
p = Axlsx::Package.new
p.use_autowidth = false
wb = p.workbook
#A Simple Workbook
wb.add_worksheet do |sheet|
times.times do
sheet << row
end
end
p.serialize("example_noautowidth.xlsx")
}
x.report('axlsx') {
p = Axlsx::Package.new
wb = p.workbook
#A Simple Workbook
wb.add_worksheet do |sheet|
times.times do
sheet << row
end
end
p.serialize("example_autowidth.xlsx")
}
x.report('axlsx_shared') {
p = Axlsx::Package.new
wb = p.workbook
#A Simple Workbook
wb.add_worksheet do |sheet|
times.times do
sheet << row
end
end
p.use_shared_strings = true
p.serialize("example_shared.xlsx")
}
x.report('axlsx_stream') {
p = Axlsx::Package.new
wb = p.workbook
# #A Simple Workbook
wb.add_worksheet do |sheet|
times.times do
sheet << row
end
end
s = p.to_stream()
File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
}
x.report('csv') {
CSV.open("example.csv", "wb") do |csv|
times.times do
csv << row
end
end
}
end
# user system total real
#axlsx_noautowidth 68.130000 1.690000 69.820000 ( 80.257108)
#axlsx 61.520000 2.290000 63.810000 ( 78.187423)
#axlsx_shared 60.170000 1.410000 61.580000 ( 73.999360)
#axlsx_stream 52.110000 1.360000 53.470000 ( 61.980672)
#csv 10.670000 0.930000 11.600000 ( 14.901387)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment