Forum: Ruby on Rails send_file VS. send_data (performance)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-04-05 13:34
Does anybody know if there is a big performance/time cost difference
between these two methods of serving a file:

------------------------------- #1
-----------------------------------------

send_file "test.png", :type => 'image/png', :disposition => 'inline'


-------------------------------
#2------------------------------------------
content = ''
File.open("test.png", "rb") do |f|
    f.each_line { |line| content += line }
end
send_data content, :type => 'image/png', :disposition => 'inline'

---------------------------------------------------------------------------

Are there any other methods? Can method #2 get faster by reading the
entire file in one sweep (as opposed to read line by line)?

Thanx in advance,
Daniel
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2006-04-05 13:44
(Received via mailing list)
Hi Daniel

Try the ruby profile library

http://www.rubycentral.com/book/lib_standard.html

You should be able to get this to show the time spent in each method.  A
simple test should show which one is faster.

Cheers
This topic is locked and can not be replied to.