Skip to content

Instantly share code, notes, and snippets.

@richdrich
richdrich / bs_vs_i.rb
Created July 19, 2020 22:01
bsearch_index vs index
require 'date'
NUM_ENTRIES = 100000
NUM_OPS=1000
a = Array.new(NUM_ENTRIES)
tstart = DateTime.now
a.fill {|n| tstart + n - NUM_ENTRIES }
t = DateTime.now
NUM_OPS.times do |n|
r = rand(NUM_ENTRIES)
@richdrich
richdrich / to_h_vs_insert.rb
Created July 19, 2020 21:59
Test performance of to_h vs insert
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"

Keybase proof

I hereby claim:

  • I am richdrich on github.
  • I am richdrich (https://keybase.io/richdrich) on keybase.
  • I have a public key whose fingerprint is DB30 A418 0848 3DCD 8C28 DB17 8C14 BD1E 22EA 656D

To claim this, I am signing this object: