* [PATCH] benchmark: add new benchmarks for hashing dsyms and fixnums
@ 2015-07-28 21:46 Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2015-07-28 21:46 UTC (permalink / raw)
To: spew
---
benchmark/bm_hash_aref_dsym.rb | 4 ++++
benchmark/bm_hash_aref_dsym_long.rb | 19 +++++++++++++++++++
benchmark/bm_hash_aref_fix.rb | 4 ++++
3 files changed, 27 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..70e8ee9
--- /dev/null
+++ b/benchmark/bm_hash_aref_dsym_long.rb
@@ -0,0 +1,19 @@
+# [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
+
+symbol_sample_array = values.sample(sample_size).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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] benchmark: add new benchmarks for hashing dsyms and fixnums
@ 2015-07-29 2:59 Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2015-07-29 2:59 UTC (permalink / raw)
To: spew
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-29 2:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-29 2:59 [PATCH] benchmark: add new benchmarks for hashing dsyms and fixnums Eric Wong
-- strict thread matches above, loose matches on Subject: below --
2015-07-28 21:46 Eric Wong
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).