dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] benchmark: add new benchmarks for hashing dsyms and fixnums
Date: Wed, 29 Jul 2015 02:59:38 +0000	[thread overview]
Message-ID: <1438138778-18308-1-git-send-email-e@80x24.org> (raw)

---
 benchmark/bm_hash_aref_dsym.rb      |  4 ++++
 benchmark/bm_hash_aref_dsym_long.rb | 21 +++++++++++++++++++++
 benchmark/bm_hash_aref_fix.rb       |  4 ++++
 3 files changed, 29 insertions(+)
 create mode 100644 benchmark/bm_hash_aref_dsym.rb
 create mode 100644 benchmark/bm_hash_aref_dsym_long.rb
 create mode 100644 benchmark/bm_hash_aref_fix.rb

diff --git a/benchmark/bm_hash_aref_dsym.rb b/benchmark/bm_hash_aref_dsym.rb
new file mode 100644
index 0000000..af4f8c3
--- /dev/null
+++ b/benchmark/bm_hash_aref_dsym.rb
@@ -0,0 +1,4 @@
+h = {}
+syms = ('a'..'z').map { |s| s.to_sym }
+syms.each { |s| h[s] = 1 }
+200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_dsym_long.rb b/benchmark/bm_hash_aref_dsym_long.rb
new file mode 100644
index 0000000..9d77593
--- /dev/null
+++ b/benchmark/bm_hash_aref_dsym_long.rb
@@ -0,0 +1,21 @@
+# [ruby-core:70129] [Bug #11396]
+collection_size = 200000
+sample_size = 10000
+
+values = (1..collection_size).to_a.map do |x|
+  "THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}"
+end
+
+symbol_hash = {}
+
+values.each do |x|
+  symbol_hash[x.to_sym] = 1
+end
+
+# use the same samples each time to minimize deviations
+rng = Random.new(0)
+symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym)
+
+3000.times do
+  symbol_sample_array.each { |x| symbol_hash[x] }
+end
diff --git a/benchmark/bm_hash_aref_fix.rb b/benchmark/bm_hash_aref_fix.rb
new file mode 100644
index 0000000..1346890
--- /dev/null
+++ b/benchmark/bm_hash_aref_fix.rb
@@ -0,0 +1,4 @@
+h = {}
+nums = (1..26).to_a
+nums.each { |i| h[i] = i }
+200_000.times { nums.each { |s| h[s] } }
-- 
EW


             reply	other threads:[~2015-07-29  2:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29  2:59 Eric Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-07-28 21:46 [PATCH] benchmark: add new benchmarks for hashing dsyms and fixnums Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438138778-18308-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).