Created
February 24, 2022 07:26
-
-
Save keymastervn/29dfb1e88cb8bca9662dab46bf07890d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
Benchmark.ips do |b| | |
hash = { | |
:type => "Employee", | |
:first_name => "Mr First", | |
:last_name => "Last Name", | |
:account_email => "[email protected]", | |
:employing_entity => "XXX Property Services Pty Ltd", | |
:employee_code => nil, | |
:location => "Head Office NSW", | |
:primary_cost_centre => "XXX Property - HQ / Head Office - NSW", | |
:additional_cost_centres => nil, | |
:employment_type => "Full-time", | |
:job_title => "CFO", | |
:team => "Head Office NSW | CEO Direct reports | Executive Team | Finance & Technology | Head Office | Head Office NSW & ACT", | |
:primary_manager_email => "[email protected]", | |
:secondary_manager_email => nil, | |
:start_date => "17/12/2020", | |
:termination_date => nil, | |
:length_of_probation => nil, | |
:company_email => "[email protected]", | |
:company_mobile => nil, | |
:company_landline => nil | |
} | |
symbolized_keys = hash.keys | |
stringified_keys = hash.keys.map(&:to_s) | |
require 'active_support/core_ext/hash/indifferent_access' | |
b.report("convert keys symbolized") do | |
symbolized_keys.each {|k| hash[k.to_sym]} | |
end | |
b.report("convert keys stringified") do | |
stringified_keys.each {|k| hash[k.to_sym]} | |
end | |
b.report("HWIA") do | |
hash = hash.with_indifferent_access | |
symbolized_keys.each {|k| hash[k]} | |
end | |
b.compare! | |
end |
Author
keymastervn
commented
Feb 24, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment