Skip to content

Commit

Permalink
Added note for ::CGI.escapeHTML performance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
randym committed Nov 25, 2012
1 parent 818821b commit e1589ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/axlsx/workbook/worksheet/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ def cast_value(v)
v ? 1 : 0
else
@type = :string
v.to_s
# TODO find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
::CGI.escapeHTML(v.to_s)
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
require 'axlsx'
require 'csv'
require 'benchmark'

row = []
input = (32..126).to_a.pack('U*').chars.to_a
20.times { row << input.shuffle.join}
times = 2000
times = 3000
Benchmark.bmbm(30) do |x|

x.report('axlsx_noautowidth') {
Expand Down
17 changes: 4 additions & 13 deletions test/profile.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
#!/usr/bin/env ruby -s
# -*- coding: utf-8 -*-

# Usage:
# > ruby test/profile.rb
# > pprof.rb --gif /tmp/axlsx_noautowidth > /tmp/axlsx_noautowidth.gif
# > pprof.rb --gif /tmp/axlsx > /tmp/axlsx.gif
# > open /tmp/axlsx_noautowidth.gif

$:.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'
require 'csv'

# require 'benchmark'
require 'perftools'
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}
times = 3000

PerfTools::CpuProfiler.start("/tmp/axlsx_noautowidth") do
PerfTools::CpuProfiler.start("/tmp/axlsx") do
p = Axlsx::Package.new
#p.use_autowidth = false
#p.use_shared_strings = true
wb = p.workbook

#A Simple Workbook

wb.add_worksheet do |sheet|
p.workbook.add_worksheet do |sheet|
times.times do
sheet << row
end
Expand Down

0 comments on commit e1589ce

Please sign in to comment.