I'd always loved using Kotlin's forEach method until I was told and I also read in some article that using the old ways of writing code is faster. Thank you for introducing me to the benchmark APIs. I won't take anyone just on their word anymore 😂
Additionally: your benchmark measures almost empty for loops. In practice, your for loop typically does several times more work inside than is taken up by the actual iteration (branch prediction + misses). So whatever difference there is, it is going to get massively reduced in practice with actual usage.
I thought that was because of the way Java allocates collection objects in memory, which is quite random if I am not mistaken. Without benchmarking, I believe you would be getting the same results if you try that in Java. Never tried it though, just a guess. In c++ I believe you won't have such problem, because of the different nature of arrays.
I've seen for these types of perf tests, you'll also get more accurate results if you warm up before you start measuring. If you don't do warm up, you'll generally see the first operations being slower than the last ones, skewing the results.
Nice one. I would also recommend this talk from Aleksey Shipilev ua-cam.com/video/x3Vlze1mUj4/v-deo.html , which explains this black hole and other black magic on JVM benchmarking.
I'd always loved using Kotlin's forEach method until I was told and I also read in some article that using the old ways of writing code is faster. Thank you for introducing me to the benchmark APIs. I won't take anyone just on their word anymore 😂
You are doing this youtube thing very nicely Sebastian 😆, catchy titles and good videos, good job mate
Also look at the bytecode
Quality content!! 👌
+1
Additionally: your benchmark measures almost empty for loops. In practice, your for loop typically does several times more work inside than is taken up by the actual iteration (branch prediction + misses). So whatever difference there is, it is going to get massively reduced in practice with actual usage.
I didn’t know the existence of the method measure and the extension. Thanks for that!
Also, how do you make the suggestion saying “Tab to complete” ?
Awesome stuff, learn lots of new things.
I thought that was because of the way Java allocates collection objects in memory, which is quite random if I am not mistaken. Without benchmarking, I believe you would be getting the same results if you try that in Java. Never tried it though, just a guess.
In c++ I believe you won't have such problem, because of the different nature of arrays.
By using 100,000 iterations you are diluting the Iterator instantiation overhead. Maybe a better test would be to execute a (0..10) loop 10,000 times.
I've seen for these types of perf tests, you'll also get more accurate results if you warm up before you start measuring. If you don't do warm up, you'll generally see the first operations being slower than the last ones, skewing the results.
Whoops, should've watched a bit further before commenting...
The flickering of the blur near your head vs background is really distracting. Maybe just disable it instead?
Good vid bud
Nice one. I would also recommend this talk from Aleksey Shipilev ua-cam.com/video/x3Vlze1mUj4/v-deo.html , which explains this black hole and other black magic on JVM benchmarking.
If you care about performance just use a serious language like Rust🚀
Why so serious? 🃏