I created a test script:
alias ItemTuple = {Int64, Int32, String, Int8, String}
class Test
property hash = Hash(Int64, ItemTuple).new
def looper
loop do
time_start = Time.now.to_unix_ms
accessed_how_many = 0_i64
hash.each do |itemid, v|
# "Modify" the tuple's 1 index, and set it to a random number between 1 and 1 million
hash[itemid] = modify_item_tuple(v, 1, rand(1..1000000))
accessed_how_many += 1
end
puts "Size of ItemTuple: #{hash.size}, Tuples re-created on the stack per second: #{accessed_how_many}, Time Taken: #{Time.now.to_unix_ms - time_start}ms"
sleep 1
end
end
def initialize
spawn looper
index = 0_i64
loop do
index += 1
hash[index] = {100_i64, 25, "", 5_i8, ""}
sleep 0.0000001
end
end
end
Test.new
class Test
def modify_item_tuple(tuple, index, new_value)
index0 = index == 0 ? new_value.to_i64 : tuple[0]
index1 = index == 1 ? new_value.to_i : tuple[1]
index2 = index == 2 ? new_value.to_s : tuple[2]
index3 = index == 3 ? new_value.to_i8 : tuple[3]
index4 = index == 4 ? new_value.to_s : tuple[4]
{index0, index1, index2, index3, index4}
end
end
Output after 20 seconds or so:
Size of ItemTuple: 1, Tuples re-created on the stack per second: 1, Time Taken: 0ms
Size of ItemTuple: 269286, Tuples re-created on the stack per second: 269286, Time Taken: 85ms
Size of ItemTuple: 522544, Tuples re-created on the stack per second: 522544, Time Taken: 194ms
Size of ItemTuple: 741516, Tuples re-created on the stack per second: 741516, Time Taken: 307ms
Size of ItemTuple: 924413, Tuples re-created on the stack per second: 924413, Time Taken: 411ms
Size of ItemTuple: 1080371, Tuples re-created on the stack per second: 1080371, Time Taken: 510ms
Size of ItemTuple: 1207186, Tuples re-created on the stack per second: 1207186, Time Taken: 607ms
Size of ItemTuple: 1308039, Tuples re-created on the stack per second: 1308039, Time Taken: 690ms
Size of ItemTuple: 1311019, Tuples re-created on the stack per second: 1311019, Time Taken: 478ms
Size of ItemTuple: 1450014, Tuples re-created on the stack per second: 1450014, Time Taken: 521ms
Size of ItemTuple: 1583022, Tuples re-created on the stack per second: 1583022, Time Taken: 577ms
Size of ItemTuple: 1703355, Tuples re-created on the stack per second: 1703355, Time Taken: 622ms
Size of ItemTuple: 1809964, Tuples re-created on the stack per second: 1809964, Time Taken: 654ms
Size of ItemTuple: 1906472, Tuples re-created on the stack per second: 1906472, Time Taken: 700ms
Size of ItemTuple: 1990610, Tuples re-created on the stack per second: 1990610, Time Taken: 734ms
Size of ItemTuple: 2064413, Tuples re-created on the stack per second: 2064413, Time Taken: 770ms
Size of ItemTuple: 2128317, Tuples re-created on the stack per second: 2128317, Time Taken: 795ms
Size of ItemTuple: 2171176, Tuples re-created on the stack per second: 2171176, Time Taken: 808ms
Size of ItemTuple: 2224756, Tuples re-created on the stack per second: 2224756, Time Taken: 830ms
Size of ItemTuple: 2272636, Tuples re-created on the stack per second: 2272636, Time Taken: 859ms
Size of ItemTuple: 2312242, Tuples re-created on the stack per second: 2312242, Time Taken: 867ms
Size of ItemTuple: 2349165, Tuples re-created on the stack per second: 2349165, Time Taken: 884ms
Size of ItemTuple: 2381380, Tuples re-created on the stack per second: 2381380, Time Taken: 902ms
Size of ItemTuple: 2407954, Tuples re-created on the stack per second: 2407954, Time Taken: 917ms
Size of ItemTuple: 2430788, Tuples re-created on the stack per second: 2430788, Time Taken: 919ms
Size of ItemTuple: 2452947, Tuples re-created on the stack per second: 2452947, Time Taken: 931ms
Size of ItemTuple: 2471942, Tuples re-created on the stack per second: 2471942, Time Taken: 938ms
Size of ItemTuple: 2488830, Tuples re-created on the stack per second: 2488830, Time Taken: 944ms
Size of ItemTuple: 2504129, Tuples re-created on the stack per second: 2504129, Time Taken: 952ms
Size of ItemTuple: 2517045, Tuples re-created on the stack per second: 2517045, Time Taken: 959ms
Size of ItemTuple: 2527984, Tuples re-created on the stack per second: 2527984, Time Taken: 970ms
Size of ItemTuple: 2535793, Tuples re-created on the stack per second: 2535793, Time Taken: 963ms
Size of ItemTuple: 2545559, Tuples re-created on the stack per second: 2545559, Time Taken: 977ms
Size of ItemTuple: 2551598, Tuples re-created on the stack per second: 2551598, Time Taken: 979ms
Size of ItemTuple: 2557123, Tuples re-created on the stack per second: 2557123, Time Taken: 982ms
Size of ItemTuple: 2561845, Tuples re-created on the stack per second: 2561845, Time Taken: 986ms
Size of ItemTuple: 2565515, Tuples re-created on the stack per second: 2565515, Time Taken: 988ms
Size of ItemTuple: 2568723, Tuples re-created on the stack per second: 2568723, Time Taken: 981ms
Size of ItemTuple: 2573921, Tuples re-created on the stack per second: 2573921, Time Taken: 980ms
Size of ItemTuple: 2579046, Tuples re-created on the stack per second: 2579046, Time Taken: 991ms
Size of ItemTuple: 2581329, Tuples re-created on the stack per second: 2581329, Time Taken: 998ms
Size of ItemTuple: 2581971, Tuples re-created on the stack per second: 2581971, Time Taken: 1017ms
Size of ItemTuple: 2581972, Tuples re-created on the stack per second: 2581972, Time Taken: 995ms
Size of ItemTuple: 2583503, Tuples re-created on the stack per second: 2583503, Time Taken: 996ms
Size of ItemTuple: 2584680, Tuples re-created on the stack per second: 2584680, Time Taken: 995ms
Size of ItemTuple: 2586037, Tuples re-created on the stack per second: 2586037, Time Taken: 997ms
Size of ItemTuple: 2586986, Tuples re-created on the stack per second: 2586986, Time Taken: 1007ms
Size of ItemTuple: 2586987, Tuples re-created on the stack per second: 2586987, Time Taken: 995ms
Size of ItemTuple: 2588384, Tuples re-created on the stack per second: 2588384, Time Taken: 1005ms
Size of ItemTuple: 2588385, Tuples re-created on the stack per second: 2588385, Time Taken: 992ms
From my understanding, it levels off after reaching around 2588385
Tuples of re-creation per second. Which is way beyond what I need! This is assuming my testing code is doing what I think it’s doing
edit: It should say, Size of Hash of ItemTuples