I wonder what happens when you just do one comparison without a loop, that time unique should ideally take more time because it is maintaining other things about the vars you have declared and also it might have to compute a hash of some sort on each var which might add a little more time, but I am unsure though, I will definitely give it a try. Really nice video.
Instead of storing 1000x of "example", what handles does is that they save 1x "example" in interning way and other 999x handles are references to it, am I getting it right?
You are not comparing the same thing. You basically create two ints and compare them, which is certainly faster. Move hash creation to inside the loop, them it will be a more fair comparison. Make hash is useful if the comparison happens multiple times.
Yes but no. It’s not comparing the same thing cause that’s the point. My understanding is: You’d create the „unique handle“ once at some point in advance to prepare for many expected (in this example) comparisons.
Umm I am trying to think in a situacion where i compare in a loop the same data. I know you do that just for explanation but we alway are compairing Dinamically data not static
Good video. Incidentally, in benchmarks written in Go 1.22+, you can replace
for i := 0; i < b.N; i++
by
for range b.N
Jap you are correct, thanks for the suggestion :D
I wonder what happens when you just do one comparison without a loop, that time unique should ideally take more time because it is maintaining other things about the vars you have declared and also it might have to compute a hash of some sort on each var which might add a little more time, but I am unsure though, I will definitely give it a try. Really nice video.
you can replace `for _ = range 10` with `for range 10`
Fair point :D Thanks for the suggestion!
Nice video,
I wonder what happen with more complex structs or with pointers
Thank you :) It will definitely improve the performance with more complex structs!
I noticed you write loops the same way i do which is forgetting that there is a range keyword 😂
I am kind of used to it in case I need `i` sometimes later :D but yeah, there is a neater way of writing this for loop.
What does second call to read memory actually show ?
shouldn't handled be garbage collected at that point?
Instead of storing 1000x of "example", what handles does is that they save 1x "example" in interning way and other 999x handles are references to it, am I getting it right?
Yes, that's correct! Essentially, there is one canonical copy of "example" and 1000 handles that reference this canonical copy.
What is ur used font ? 🎉🎉🎉
It's the Monaspace font :)
You are not comparing the same thing.
You basically create two ints and compare them, which is certainly faster.
Move hash creation to inside the loop, them it will be a more fair comparison.
Make hash is useful if the comparison happens multiple times.
Yes but no. It’s not comparing the same thing cause that’s the point.
My understanding is: You’d create the „unique handle“ once at some point in advance to prepare for many expected (in this example) comparisons.
Umm I am trying to think in a situacion where i compare in a loop the same data. I know you do that just for explanation but we alway are compairing
Dinamically data not static