Open do-m-en opened 5 years ago
I will look into this after the Cologne WG21 meeting.
To go over it quickly, something like this can be achieved with scn::getline
, in a similar fashion to std::getline
with strings, although you'd need to jump through a few hoops. Your use case seems like quite a common one, however, and perhaps doing something like that should be easier. As I said, I'll look into it in about a week.
I created a repo comparing your above example with a somewhat equivalent example with scnlib: https://github.com/eliaskosunen/scnlib-spirit-benchmark
Spirit is almost twice as fast in this example. This is because scnlib doesn't support this use case well; there's a lot of boilerplate compared to spirit, and the input needs to be scanned and the stream needs to be allocated twice. I consider this a bug, and this is something that needs to be fixed before the next release.
Actually, my benchmarks were a little off; the time difference is ~25%. This is still a bug, though
By making string_view
work with scn::getline
the difference is now ~15%
At a first glance this library seems to be targeting simple pattern parsing and not grammar parsing (that's the one that I need most of the time) but simple parsing can also be done with boost spirit x3 so I use that library for more or less for all string parsing.
Since this is library is now the basis of a C++ standard proposal I'd be interested in the runtime performance compared to the library that I would like to see being the basis of a standardization efforts - boost::spirit::x3.
I wasn't able to find an example but my basic pattern is usually not a single item but a list of items of unknown length so comparison with something like this would be nice:
This can be executed inside https://wandbox.org/