Sha256: f2f254182b2facf4ec9105148307101660b16db6ee8ef4c8365f684b4b9b97af

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'bundler/setup'
require 'fileutils'
require 'tmpdir'
require_relative '../lib/fast_excel'

# gem install axlsx benchmark-ips write_xlsx

require "benchmark/ips"
require 'axlsx'
require 'write_xlsx'
require 'process_memory'

require_relative 'init'

def write_fast_excel_20k
  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)
  end
  workbook.read_string
end

def write_xlsx_20k
  filename = "#{Dir.mktmpdir}/write_xlsx.xslx"
  workbook = WriteXLSX.new(filename)
  worksheet = workbook.add_worksheet
  HEADERS.each_with_index do |value, i|
    worksheet.write(0, i, value)
  end
  DATA.each_with_index do |row, row_num|
    worksheet.write_number(row_num + 1, 0, row[0])
    worksheet.write_string(row_num + 1, 1, row[1])
    worksheet.write_number(row_num + 1, 2, row[2])
    worksheet.write_number(row_num + 1, 3, row[3])
    worksheet.write_number(row_num + 1, 4, row[4])
  end
  workbook.close
  File.open(filename, 'rb', &:read)
  File.delete(filename)
end

def write_axslx_20k
  filename = "#{Dir.mktmpdir}/axslx.xslx"
  Axlsx::Package.new do |package|
    package.use_autowidth = false
    package.workbook.add_worksheet do |sheet|
      sheet.add_row(HEADERS)
      DATA.each do |row|
        sheet.add_row(row)
      end
    end
    package.serialize(filename)
    File.open(filename, 'rb', &:read)
    File.delete(filename)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fast_excel-0.2.0 benchmarks/init.rb