diff options
| author | Paul Kmiec <[email protected]> | 2023-04-29 16:22:39 -0700 |
|---|---|---|
| committer | Paul Kmiec <[email protected]> | 2023-05-05 09:29:58 -0700 |
| commit | 1c355c83a9603f835dfe59ef4473df2b8cc3534c (patch) | |
| tree | b1dc4d05e5cd19ce48d0b86dc5ac8e8140a465a3 | |
| parent | 916ba45a77302bcd6e81f2a61a6cff6a2f1f8367 (diff) | |
| download | caxlsx-1c355c83a9603f835dfe59ef4473df2b8cc3534c.tar.gz caxlsx-1c355c83a9603f835dfe59ef4473df2b8cc3534c.zip | |
Improve benchmarking / profiling
Added zip_command variant to benchmark.rb and added profile_memory.rb based on
the `memory_profiler` gem.
| -rw-r--r-- | Gemfile | 3 | ||||
| -rwxr-xr-x | test/benchmark.rb | 25 | ||||
| -rwxr-xr-x | test/profile.rb | 10 | ||||
| -rwxr-xr-x | test/profile_memory.rb | 27 |
4 files changed, 54 insertions, 11 deletions
@@ -17,5 +17,6 @@ group :test do end group :profile do - gem 'ruby-prof', :platforms => :ruby + gem 'memory_profiler' + gem 'ruby-prof', platforms: :ruby end diff --git a/test/benchmark.rb b/test/benchmark.rb index 38dcc8fc..d5ccdf64 100755 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -5,11 +5,14 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'axlsx' require 'csv' require 'benchmark' -Axlsx::trust_input = true +# Axlsx::trust_input = true row = [] -input = (32..126).to_a.pack('U*').chars.to_a -20.times { row << input.shuffle.join } +input1 = (32..126).to_a.pack('U*').chars.to_a # these will need to be escaped +input2 = (65..122).to_a.pack('U*').chars.to_a # these do not need to be escaped +10.times { row << input1.shuffle.join } +10.times { row << input2.shuffle.join } times = 3000 + Benchmark.bmbm(30) do |x| x.report('axlsx_noautowidth') do p = Axlsx::Package.new @@ -24,7 +27,7 @@ Benchmark.bmbm(30) do |x| p.serialize("example_noautowidth.xlsx") end - x.report('axlsx') do + x.report('axlsx_autowidth') do p = Axlsx::Package.new p.workbook do |wb| wb.add_worksheet do |sheet| @@ -62,6 +65,18 @@ Benchmark.bmbm(30) do |x| File.binwrite('example_streamed.xlsx', s.read) end + x.report('axlsx_zip_command') do + p = Axlsx::Package.new + p.workbook do |wb| + wb.add_worksheet do |sheet| + times.times do + sheet << row + end + end + end + p.serialize("example_zip_command.xlsx", zip_command: 'zip') + end + x.report('csv') do CSV.open("example.csv", "wb") do |csv| times.times do @@ -70,4 +85,4 @@ Benchmark.bmbm(30) do |x| end end end -File.delete("example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx") +File.delete("example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx", "example_zip_command.xlsx") diff --git a/test/profile.rb b/test/profile.rb index 498f2619..adbc7ab9 100755 --- a/test/profile.rb +++ b/test/profile.rb @@ -4,12 +4,12 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'axlsx' require 'ruby-prof' -# RubyProf.measure_mode = RubyProf::MEMORY -# + row = [] -# Taking worst case scenario of all string data -input = (32..126).to_a.pack('U*').chars.to_a -20.times { row << input.shuffle.join } +input1 = (32..126).to_a.pack('U*').chars.to_a # these will need to be escaped +input2 = (65..122).to_a.pack('U*').chars.to_a # these do not need to be escaped +10.times { row << input1.shuffle.join } +10.times { row << input2.shuffle.join } profile = RubyProf.profile do p = Axlsx::Package.new diff --git a/test/profile_memory.rb b/test/profile_memory.rb new file mode 100755 index 00000000..15547b37 --- /dev/null +++ b/test/profile_memory.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby -s +# frozen_string_literal: true + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'axlsx' +require 'memory_profiler' + +# Axlsx.trust_input = true + +row = [] +input1 = (32..126).to_a.pack('U*').chars.to_a # these will need to be escaped +input2 = (65..122).to_a.pack('U*').chars.to_a # these do not need to be escaped +10.times { row << input1.shuffle.join } +10.times { row << input2.shuffle.join } + +report = MemoryProfiler.report do + p = Axlsx::Package.new + p.workbook.add_worksheet do |sheet| + 10_000.times do + sheet << row + end + end + p.serialize("example_memory.xlsx", zip_command: 'zip') +end +report.pretty_print + +File.delete("example_memory.xlsx") |
