Created
July 19, 2020 21:59
-
-
Save richdrich/cc3dd334a38946d1b47baa3f8af35e97 to your computer and use it in GitHub Desktop.
Test performance of to_h vs insert
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 'date' | |
NUM_ENTRIES = 100000 | |
t = DateTime.now | |
h = (0..NUM_ENTRIES).each.map do |n| | |
[n, 25 * n] | |
end.to_h | |
puts "#{(DateTime.now - t).to_f * 1000 * 86400} ms to populate by to_h" | |
t = DateTime.now | |
h = {} | |
(0..NUM_ENTRIES).each do |n| | |
h[n] = 25 * n | |
end | |
puts "#{(DateTime.now - t).to_f * 1000 * 86400} ms to populate by insert" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment