public
Created

axlsx benchmarks

  • Download Gist
benchmark.rb
Ruby
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#!/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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.