Mi è stato chiesto di documentare le mie osservazioni sulle performance della formattazione di oggetti di tipo Date, DateTime, Time.
A seguito una serie di test di verifica delle prestazioni.Questi test sono stati eseguiti su un DualCore T9500 (2.6ghz) 4 GB ram sistema operativo Ubuntu 8.10 intrepid.
Questo il codice usato per eseguire i test:
require ‘ruby-prof’
MAX = 50000
class CodeProfiler
def self.time_this(comment, &block)
RubyProf.measure_mode = RubyProf::PROCESS_TIME
RubyProf.start
yield
result = RubyProf.stop
puts “\nTimings for #{comment}”
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT, 0)
end
end
CodeProfiler.time_this(“Class Date -> strftime(\”%d/%m/%Y\”):”) {
x = ”
t = Date.new()
(0..MAX).each do |i|
x = t.strftime(“%d/%m/%Y”)
end
}
CodeProfiler.time_this(‘Class Date -> #{t.day}/#{t.month}/#{t.year}:’) {
x = ”
t = Date.new()
(0..MAX).each do |i|
x = “#{t.day}/#{t.month}/#{t.year}”
end
}
CodeProfiler.time_this(“Class DateTime -> strftime(\”%d/%m/%Y %H:%M\”):”) {
x = ”
t = DateTime.new()
(0..MAX).each do |i|
x = t.strftime(“%d/%m/%Y %H:%M”)
end
}
CodeProfiler.time_this(‘Class DateTime -> #{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}:’) {
x = ”
t = DateTime.new()
(0..MAX).each do |i|
x = “#{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}”
end
}
CodeProfiler.time_this(“Class Time -> strftime(\”%d/%m/%Y %H:%M\”):”) {
x = ”
t = Time.new()
(0..MAX).each do |i|
x = t.strftime(“%d/%m/%Y %H:%M”)
end
}
CodeProfiler.time_this(‘Class Time -> #{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}:’) {
x = ”
t = Time.new()
(0..MAX).each do |i|
x = “#{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}”
end
}
Risultati
Timings for Class Date -> strftime(“%d/%m/%Y”):
Thread ID: 70286299744000
Total: 14.590000
Timings for Class Date -> #{t.day}/#{t.month}/#{t.year}:
Thread ID: 70286299744000
Total: 0.880000
Timings for Class DateTime -> strftime(“%d/%m/%Y %H:%M”):
Thread ID: 70286299744000
Total: 22.800000
Timings for Class DateTime -> #{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}:
Thread ID: 70286299744000
Total: 1.500000
Timings for Class Time -> strftime(“%d/%m/%Y %H:%M”):
Thread ID: 70286299744000
Total: 0.190000
Timings for Class Time -> #{t.day}/#{t.month}/#{t.year} #{t.hour}:#{t.min}:
Thread ID: 70286299744000
Total: 0.550000
Conclusioni
Da questi test si può ricavare come solamente la classe time sia performante nell’uso del metodo strftime, sconsiglio quindi l’uso di questo metodo su oggetti di tipo Date e DateTime.









If you’re still on the fence: grab your favorite earphones, head down to a Best Buy and ask to plug them into a Zune then an iPod and see which one sounds better to you, and which interface makes you smile more. Then you’ll know which is right for you.
This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like ‘Mixview’ that let you quickly see related albums, songs, or other users related to what you’re listening to. Clicking on one of those will center on that item, and another set of “neighbors” will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune “Social” is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.
I don’t even know how I finished up right here, however I believed this submit was once good. I do not know who you are but certainly you are going to a famous blogger when you are not already
Cheers!
I am not sure where you are getting your info, but great topic. I needs to spend some time learning more or understanding more. Thanks for great information I was looking for this information for my mission.