Project

General

Profile

Feature #15251 ยป test_hash_keys_deduped.rb

chopraanmol1 (Anmol Chopra), 10/24/2018 01:03 PM

 
1

    
2
def string_literal
3
  +"string_literal"
4
end
5

    
6
def interpolated_string
7
  underscore = -"_"
8
  "interpolated#{underscore}string"
9
end
10

    
11
def string_times_3
12
  "string times 3 " * 3
13
end
14

    
15
def string_times_1
16
  "string times 1" * 1
17
end
18

    
19
def string_add
20
  "string" + " " + "add"
21
end
22

    
23
def appended_string
24
  str = "string"
25
  str << " append"
26
  str
27
end
28

    
29
def string_arr
30
  [string_literal, string_times_1, string_times_3, interpolated_string, string_add, appended_string]
31
end
32

    
33
def fstring_arr
34
  string_arr.each{|str| -str}
35
end
36

    
37
def print_hash_key_count n = 100
38
  n.times.collect{ string_arr.each.with_object({}){|str, hsh| hsh[str] = nil}.keys }.transpose.each do |str_arrs|
39
    puts "#{str_arrs.first} => #{str_arrs.uniq(&:__id__).count}"
40
  end
41
end
42

    
43
print_hash_key_count
44

    
45
puts "-+" * 20
46
puts "fstring"
47
puts "-+" * 20
48
fstring_arr
49
print_hash_key_count
50

    
51
puts "-+" * 20
52
puts "fstring + GC"
53
puts "-+" * 20
54
fstring_arr
55
GC.start
56
print_hash_key_count
57

    
58