ITADN

`seek_ip_end` for fairness

#121Closedthe-moisrex 创建于 2025-12-28
T
the-moisrexcommented
I wanted to add my own implementation to your benchmark for ipv4 parsing that I noticed we're doing ` const char *q = seek_ip_end(p, pend);` everywhere except for the `parse_ip_fastfloat` and `parse_ip_std_fromchars`. We should use it so the benchmarks are fair: ```cpp template <parse_method use_standard> fastfloat_really_inline std::expected<uint32_t, parse_error> simple_parse_ip_line(const char *p, const char *pend) { const char *q = seek_ip_end(p, pend); const char *current = p; uint32_t ip = 0; for (int i = 0; i < 4; ++i) { uint8_t value; if constexpr (use_standard == parse_method::standard) { auto r = std::from_chars(current, q, value); if (r.ec != std::errc()) { return std::unexpected(parse_error::invalid_format); } current = r.ptr; } else if constexpr (use_standard == parse_method::fast_float) { auto r = fast_float::from_chars(current, q, value); if (r.ec != std::errc()) { return std::unexpected(parse_error::invalid_format); } current = r.ptr; } ip = (ip << 8) | value; if (i < 3) { if (current == pend || *current++ != '.') { return std::unexpected(parse_error::invalid_format); } } } return ip; } ``` My results after the change: ``` memcpy baseline : 79.00 GB/s 4937.5 Mip/s 0.20 ns/ip 5.59 GHz 1.13 c/ip 0.02 i/ip 0.07 c/b 0.00 i/b 0.01 i/c just_seek_ip_end (no parse) : 1.35 GB/s 84.3 Mip/s 11.86 ns/ip 5.50 GHz 65.26 c/ip 94.57 i/ip 4.08 c/b 5.91 i/b 1.45 i/c parse_ip_std_fromchars : 0.76 GB/s 47.2 Mip/s 21.17 ns/ip 5.50 GHz 116.52 c/ip 316.95 i/ip 7.28 c/b 19.81 i/b 2.72 i/c parse_ip_fastfloat : 0.78 GB/s 48.7 Mip/s 20.52 ns/ip 5.50 GHz 112.94 c/ip 324.04 i/ip 7.06 c/b 20.25 i/b 2.87 i/c parse_boost_asio : 0.33 GB/s 20.4 Mip/s 49.01 ns/ip 5.50 GHz 269.65 c/ip 952.03 i/ip 16.85 c/b 59.50 i/b 3.53 i/c parse_manual : 0.80 GB/s 50.2 Mip/s 19.92 ns/ip 5.50 GHz 109.63 c/ip 307.36 i/ip 6.85 c/b 19.21 i/b 2.80 i/c parse_manual_unrolled : 0.93 GB/s 58.0 Mip/s 17.23 ns/ip 5.50 GHz 94.84 c/ip 249.23 i/ip 5.93 c/b 15.58 i/b 2.63 i/c webpp : 0.88 GB/s 54.9 Mip/s 18.21 ns/ip 5.50 GHz 100.21 c/ip 283.38 i/ip 6.26 c/b 17.71 i/b 2.83 i/c ``` The `webpp` one is my own `ipv4` implementation.
关闭于 2025-12-28 1 条评论