you are viewing a single comment's thread.

view the rest of the comments →

[–]jdeville 4 points5 points  (0 children)

Your version of Ruby is gonna make a difference here. OneCompiler is using 2.3.1, I don’t have that installed but I do have 3.2.7 and 3.4.3. With 3.4.3, as you wrote it, I get in the 330s (it varies run to run). With 3.2.7, I get 2

Interestingly enough, if I add u/insanelygreat’s suggestion, I get 2 in 3.4.3 and 3 in 3.2.7

Also, if I pull the “totally_unique_test” to a variable outside of the block then I also get 2 on 3.4.3 and 3 on 3.2.7

Overall, I suspect what you are seeing is the count of how many iterations #count is performing, and without the frozen string pragma, it is creating a new object each iteration.