[ruby-it] 100% cpu
Alessandro Scolavino
scolas a gmail.com
Lun 2 Mar 2009 11:41:55 CET
Alessandro Scolavino wrote:
> il problema è sulla string concatenation,
>
> qualcuno ha idea su come velocizzarlo??
>
> ho provato con :
>
> pippo << "abcdef...."
> pippo = pippo + "abcdef...."
> pippo = "#{pippo}abcdef...."
>
> stessi risultati... circa 10 secondi per 200 righe ...
per chiarezza, il ciclo che sto usando è:
first.upto(last) do |cur|
cal << %(<td>#{button({ :nocenter => true, :class => "action
week_selector", :id => "week_View_#{cur.strftime("%W")}_#{cur.year}",
:alt => "#{_('Show Week')} #{cur.strftime("%W")}" })}</td>) if cur.wday
== first_weekday
cell_text, cell_attrs = block.call(cur)
cell_text ||= cur.mday
cell_attrs ||= {:class => options[:day_class]}
cell_attrs[:class] += " weekendDay" if [0, 6].include?(cur.wday)
cell_attrs[:class] += " today" if (cur == Date.today) and
options[:show_today]
cell_attrs = cell_attrs.map {|k, v| %(#{k}="#{v}") }.join(" ")
cal << %(<td #{cell_attrs}><div class="app_day"><span
class="day_number">#{cur.day}</span><div class="calendar_cell
#{cur.strftime("%d_%m_%Y")}">
#{ clerk_calendar.have_appo_day?(cur) ? %(<img
onclick="show_appo(this)" class="month_appo #{cur.strftime("%d_%m_%Y")}"
src="/images/icon/month_appo.png" />) : ""}
</div></td>)
cal << "</tr><tr>" if cur.wday == last_weekday
end
fa parte di un plugin (ovviamente modificato per le mie esigenze), e
costruisce una vista mensile per un calendario.
Questo pezzo di codice ci mette circa 7 secondi (sono ben 30 cicli) il
tempo delle chiamate ai vari metodi è trascurabile (vicino a 0)
--
Posted via http://www.ruby-forum.com/.
More information about the Ml
mailing list