Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Created July 2, 2019 13:43
Show Gist options
  • Save hkurokawa/c973f73a05dcfa23c6b5bb41017cdd1f to your computer and use it in GitHub Desktop.
Save hkurokawa/c973f73a05dcfa23c6b5bb41017cdd1f to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'priority_queue'
#require 'profile'
M = 64
N = 153600
pq = PriorityQueue.new
list = Array.new(N) { |i| i }.shuffle
time = Benchmark.realtime do
(1..M).each {
list.each { |i| pq.push(i, i) }
(1..N).each { pq.delete_min }
}
end
p time # 25.72565756700351
#
# Linux 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment