3 ms·
Ok, I dived into the rabbit hole a bit and found this: https://github.com/rosetta-rs/string-rosetta-rs?tab=readme-ov-file https://github.com/rosetta-rs/string-
by brigadier132 2y ago
Ok, I dived into the rabbit hole a bit and found this:
https://github.com/rosetta-rs/string-rosetta-rs?tab=readme-ov-file https://github.com/rosetta-rs/string-rosetta-rs?tab=readme-o...
Click the charts for actually readable data.
From a quick scan, it seems like hipstr is the current fastest string implementation and is actively maintained.
- IshKebab 2y agoAnd has the best name!
- skavi 2y agoThose benchmarks aren’t great. A real world-ish workload made generic over all these types would provide much more interesting results. Especially if heap usage was also tracked.
- dathinab 2y agothe author has some recommendations, to quote formatting): > Suggestions: > > Generally, String > If you deal mostly with string literals but want some flexibility (like clap), generally you'll want Cow<'static, str> > If a profiler says your strings are a problem: > Try different crates and settings for that crate out with a profiler > O(1) clones are important when doing a lot of clones. > For one-off allocations, they are slower. > For short-lived programs, look into string interning i.e. author thinks you should profile with your own use case EDIT: Not sure why HN removes indention between a leading > and the start of the text, makes quoting unnecessary hard
- samatman 2y agoHTML doesn't do indentation. I typed four spaces between every word in these sentences.
- dathinab 2y agobut HN doesn't provide me with a HTML input field but a text input field and HTML has stuff like <blockquote> absent from HN input format and properly converting user input is a bread and butter task of anything displaying user content so HTML collapsing whitespace is really meaningless for the argument IMHO
- masklinn 2y ago> Not sure why HN removes indention between a leading > and the start of the text, makes quoting unnecessary hard Because HN’s markup is the most dreary, half-assed, and useless one in the history of lightweight markups. HN will remove a bunch of characters it doesn’t like because they might be used for fun, parse two+ newlines as a paragraph break, 4-indent as a literal block, and mis-parse * as emphasis. That’s it. So you get all the drawbacks of HTML with almost none of the tools provided by even just the original markdown. No quoting, no line breaks, no lists, no inline code, …
- wizzwizz4 2y ago2-indent is a literal block. 4-indent also is, but only because it's a 2-indent. HN markup also supports \-escapes (so you can write \*hello\* to get *hello*), but they grow linearly, not exponentially, with repeated escapes (\\\* becomes \\*). It also truncates long URLs in display, and it handles a single pair of parentheses in them (so you can write https://example.com/print(%22Hello,%20world%21%22) https://example.com/print(%22Hello,%20world%21%22)). But I think that's all.
- epage 2y agoReal world benchmarks also wouldn't be great because they would be showing how well it works in someone else's program, rather than yours. This at least gives you an idea of what the relative cost of different operations are so you can consider what are frequent operations in your program and then benchmark a couple from there, rather than everything.
- epage 2y agoAlso, smol_str was removed from the comparison because matklad, the author of smol_str, suggests ecow > I’d rather say the opposite: users of those crates should switch to ecow. It is exactly what smol_str would have been, if it were a proper crate with a stable API, rather than an implementation detail of rust-analyzer. > > It’s a drop-in replacement for String, with O(1) clone and SSO, and I believe this is all you need. Other crates either have needlessly restricted API (no mutation), questionable implementation choices, or a bunch of ad hoc traits in the API. https://www.reddit.com/r/rust/comments/117ksvr/ecow_compact_cloneonwrite_vector_and_string/j9eh35d/ https://www.reddit.com/r/rust/comments/117ksvr/ecow_compact_...