Module: Nokogiri::XML
- Defined in:
- lib/kitchen/patches/nokogiri.rb,
lib/kitchen/patches/nokogiri_profiling.rb
Defined Under Namespace
Classes: Document, Node, XPathContext
Constant Summary collapse
- PROFILE_DATA =
rubocop:disable Style/MutableConstant
{}
Class Method Summary collapse
-
.print_profile_data ⇒ Object
Patches inside Nokogiri to count, time, and print searches.
Class Method Details
.print_profile_data ⇒ Object
Patches inside Nokogiri to count, time, and print searches. At end of baking
you can puts Nokogiri::XML::PROFILE_DATA to see the totals. The counts
hash is defined outside of the if block so that code that prints it doesn't
explode if run without the env var. The print_profile_data method is also
provided for a nice printout
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kitchen/patches/nokogiri_profiling.rb', line 21 def self.print_profile_data total_duration = 0 sorted_profile_data = PROFILE_DATA.sort_by { |_, data| data[:time] / data[:count] }.reverse puts "\nSearch Profile Data" puts '-----------------------------------------------------------------' puts "#{'Total Time (ms)'.ljust(17)}#{'Avg Time (ms)'.ljust(15)}#{'Count'.ljust(7)}Query" puts '-----------------------------------------------------------------' sorted_profile_data.each do |search_path, data| total_time = format('%0.4f', (data[:time] * 1000)) avg_time = format('%0.4f', ((data[:time] / data[:count]) * 1000)) puts total_time.ljust(17) + avg_time.to_s.ljust(15) + data[:count].to_s.ljust(7) + \ search_path total_duration += data[:time] * 1000 end puts "\nTotal time across all searches (ms): #{total_duration}" end |