mariusbancila / stduuid

A C++17 cross-platform implementation for UUIDs
MIT License
742 stars 112 forks source link

uuids::to_string() faster implementation #48

Closed rickyviking closed 2 years ago

rickyviking commented 2 years ago

Benchmark on function uuids::to_string() shows poor performance, probably due to the usage of formatted streams for the conversion. An alternative approach based on this implementation shows a huge performance gain: benchmarks run for 1'000'000 entries (on i7-7820X 3.6GHz):

operation millisecs
create uuids 85
to_string() - original 5183
to_string() - alternative 151

Are you open to consider the switch to the more efficient implementation?

This is somehow related to issue #41, but it's more correct to keep this topic independent, as the alternative hash function proposed in #41 is no more based on string conversion and performs better anyway.

mariusbancila commented 2 years ago

It's a good suggestion.

mariusbancila commented 2 years ago

Implemented a faster version of to_string().

rickyviking commented 2 years ago

Hi @mariusbancila, thank you, I confirm the benchmarks I run on your new implementation are in line with what I reported above. I've also created a PR #51 to implement the stream operator in term of the no fast to_string() method, rather than streaming individual chuncks.

mariusbancila commented 2 years ago

Thanks for the PR. It's merged.