In this video I introduce you to rust microbenchmarking with cargo criterion, and answer the question "Should I use to_string() or to_owned() on my &str?" You can get the code here: github.com/mas...
Пікірлер: 14
@masmullin2 жыл бұрын
Lol Bennchmarks. I'm keeping it.
@karelhrkal87532 жыл бұрын
4:10 you should use Vec::with_capacity when you know how big the vector is going to be to prevent unnecessary allocations. In this case, that should be len * symbol.len_utf8(). Also you are encoding the char to utf8 in every iteration of the loop, which is like ... why.
@luckystrike91 Жыл бұрын
I have another question about performance: why BufReader::lines() returns String? I don't need a growable buffer, i need an immutable view into string content!
@Wodziwob Жыл бұрын
Awesome breakdown. I'm new to rust and I've heard tales of the speed difference so I really appreciate seeing the truth. Fwiw in the part about the dictionary definition of idiomatic, I read "distinctive idiomatic dialogue" as an example of how to use idiomatic in a sentence, not an example of idiomatic speech itself. Or maybe the dictionary author is a rustacean, since they say "idiomatic" so much.
@qwertyqwerty-jp8pr2 жыл бұрын
I think ToString as something being like Display but put it inside a string. ToOwned is more clear if you want to turn &str into String because you are not casting to string, you're simply trying to take ownership.
@samuelgunter Жыл бұрын
I'd look at the generated assembly and see if it's exactly the same, that'd be an easy way to tell
@0xccd2 жыл бұрын
Existencial question answered. Thanks!
@loarca112 жыл бұрын
Such a nice presentation, for real man, I really appreciate it!
@okarakoo2 жыл бұрын
Real interesting, thank you. As an aside, what's the coding font you are using? The curly brackets look sharp! :-)