benchmarks/1k_rows.rb in fast_excel-0.2.5 vs benchmarks/1k_rows.rb in fast_excel-0.2.6
- old
+ new
@@ -1,24 +1,24 @@
require_relative 'init'
-HEADERS = ["id", "name", "age", "date"]
+HEADERS = ["id", "name", "age", "date"].freeze
DATA = []
1000.times do |n|
DATA << [n, "String string #{n}", (n * rand * 10).round, Time.at(n * 1000 + 1492922688)]
end
Benchmark.ips do |x|
- x.config(time: 10, warmup: 2)
+ x.config(time: 10, warmup: 40)
x.report("FastExcel") do
workbook = FastExcel.open(constant_memory: true)
worksheet = workbook.add_worksheet("benchmark")
worksheet.write_row(0, HEADERS)
- DATA.each_with_index do |row, i|
- worksheet.write_row(i + 1, row)
+ DATA.each do |row|
+ worksheet.append_row(row)
end
workbook.read_string
end
x.report("Axlsx") do
@@ -51,9 +51,22 @@
worksheet.write_number(row_num + 1, 3, row[3])
end
workbook.close
File.open(filename, 'rb', &:read)
File.delete(filename)
+ end
+
+ x.report("xlsxtream") do
+ filename = "#{Dir.mktmpdir}/xlsxtream.xlsx"
+
+ Xlsxtream::Workbook.open(filename) do |xlsx|
+ xlsx.write_worksheet do |sheet|
+ sheet << HEADERS
+ DATA.each do |row|
+ sheet << row
+ end
+ end
+ end
end
x.compare!
end