-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Huge performance improvements, largely by abandoning ruby's `Array` and holding all entries (both score and value) in a (simpler?) C array. Some scenarios are 1.3x faster (low N) to 3.2x faster (high N)! Also: Refactored the pure ruby benchmark implementation for a 15-20% improvement (w/o JIT). I realized I should use realloc instead of calloc + memcpy + free, although that didn't amount to much if any a performance gain. I also discovered `priority_queue_cxx` and added it to the benchmarks. I was pleasantly surprised to find that (with the latest improvements), `d_heap` now outpaces gcc's C++ STL priority_queue, as used by that gem. n.b. there are definitely large slowdowns above ~10M entries, mostly I believe because of memory growth spreading the heap across multiple pages. Other data structures might be useful (e.g. timing wheel) at that size.
- Loading branch information
Showing
17 changed files
with
914 additions
and
730 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "perf" | ||
|
||
system("#{RbConfig.ruby} bin/rake compile", err: :out, exception: true) | ||
require "d_heap/benchmarks" | ||
include DHeap::Benchmarks # rubocop:disable Style/MixinUsage | ||
fill_random_vals | ||
|
||
n = ENV.fetch("BENCH_N", 5_000_000).to_i | ||
# interval = ENV.fetch("PROF_INTERVAL", 100).to_i # measured in μs | ||
|
||
i = 0 | ||
|
||
q = initq RbHeap | ||
n.times { q << n } | ||
q.clear | ||
|
||
Perf.record do | ||
while i < n | ||
q << random_val | ||
i += 1 | ||
end | ||
while 0 < i # rubocop:disable Style/NumericPredicate | ||
q.pop | ||
i -= 1 | ||
end | ||
end |
Oops, something went wrong.