module Nokogiri::XML
Constants
- PROFILE_DATA
rubocop:disable Style/MutableConstant
Public Class Methods
print_profile_data()
click to toggle source
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
# 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