Have parse_number_f64 use the Eisel algorithm

The algorithm is discussed at
https://lemire.me/blog/2020/03/10/fast-float-parsing-in-practice/

----

Binary size, before:
27848 gen/lib/c/clang-5.0-dynamic/wuffs-base-f64conv.lo
28040 gen/lib/c/clang-5.0-static/wuffs-base-f64conv.o
30392 gen/lib/c/gcc-dynamic/wuffs-base-f64conv.lo
30392 gen/lib/c/gcc-static/wuffs-base-f64conv.o

After:
29416 gen/lib/c/clang-5.0-dynamic/wuffs-base-f64conv.lo
29688 gen/lib/c/clang-5.0-static/wuffs-base-f64conv.o
31792 gen/lib/c/gcc-dynamic/wuffs-base-f64conv.lo
31792 gen/lib/c/gcc-static/wuffs-base-f64conv.o

The binary size difference does not account for the powers-of-10 table,
which was expanded in a previous commit in anticipation of this one. A
future commit will also remove some of the other f64 parser code used
before implementing the Eisel algorithm.

----

Processing citylots.json from github.com/zemirco/sf-city-lots-json
$ g++ -O3 script/process-json-numbers.c
$ time ./a.out -parse-number-f64 < citylots.json
Before/After:
real    0m1.231s
real	0m1.031s

The difference with and without -parse-number-f64 measures how much time
is spent in the parse_number_f64 function. Before: 424ms, after: 224ms.
$ time ./a.out                   < citylots.json
real	0m0.807s

Similarly, for canada.json from github.com/miloyip/nativejson-benchmark
$ time ./a.out -parse-number-f64 < canada.json
Before/After:
real	0m0.023s
real	0m0.017s
$ time ./a.out                   < canada.json
real	0m0.013s
Time spent in parse_number_f64, before: 10ms, after: 4ms.

----

name                                                old time/op  new time/op   delta
wuffs_strconv_parse_number_f64_1_lsh53_add0/clang5  77.0ns ± 0%   37.0ns ± 0%  -51.95%  (p=0.029 n=4+4)
wuffs_strconv_parse_number_f64_1_lsh53_add1/clang5   690ns ± 0%    725ns ± 2%   +4.95%  (p=0.008 n=5+5)
wuffs_strconv_parse_number_f64_pi_long/clang5       92.0ns ± 0%  136.0ns ± 2%  +47.83%  (p=0.016 n=4+5)
wuffs_strconv_parse_number_f64_pi_short/clang5      35.0ns ± 3%   18.0ns ± 0%  -48.57%  (p=0.008 n=5+5)
wuffs_strconv_parse_number_f64_1_lsh53_add0/gcc7    67.0ns ± 0%   34.0ns ± 0%  -49.25%  (p=0.000 n=5+4)
wuffs_strconv_parse_number_f64_1_lsh53_add1/gcc7     712ns ± 0%    760ns ± 2%   +6.72%  (p=0.008 n=5+5)
wuffs_strconv_parse_number_f64_pi_long/gcc7         88.4ns ± 1%  116.2ns ± 3%  +31.45%  (p=0.008 n=5+5)
wuffs_strconv_parse_number_f64_pi_short/gcc7        32.6ns ± 2%   21.4ns ± 7%  -34.36%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2020-07-07 15:27:51 +10:00
1 parent 1bc98b6035
commit 86093c8194
5 files changed
+814 -61

No files matched your search

+25
View File
@@ -613,6 +613,7 @@ test_wuffs_strconv_parse_number_f64() {
{.want = 0x0000000000000000, .str = "+0.0"},
{.want = 0x0000000000000000, .str = "0"},
{.want = 0x0000000000000000, .str = "0e0"},
{.want = 0x0000000000000000, .str = "0e99"},
{.want = 0x0000000000000000, .str = "1e-332"},
{.want = 0x0000000000000001, .str = "4.9406564584124654e-324"},
{.want = 0x0000000000000002, .str = "9.8813129168249309e-324"},
@@ -642,6 +643,8 @@ test_wuffs_strconv_parse_number_f64() {
{.want = 0x400921FB54442D11, .str = "3.14159265358979"},
{.want = 0x400921FB54442D18, .str = "3.141592653589793"},
{.want = 0x400921FB54442D18, .str = "3.141592653589793238462643383279"},
{.want = 0x400921FB54442D18,
.str = "3.1415926535897932384626433832795028841971693993751"},
{.want = 0x400C000000000000, .str = "3.5"},
{.want = 0x4014000000000000, .str = "5"},
{.want = 0x4036000000000000, .str = "22"},
@@ -667,13 +670,17 @@ test_wuffs_strconv_parse_number_f64() {
{.want = 0x4340000000000002, .str = "9007199254740995"},
{.want = 0x4340000000000002, .str = "9007199254740996"},
{.want = 0x4340000000000002, .str = "9_007__199_254__740_996"},
{.want = 0x4370000000000000, .str = "7.2057594037927933e+16"},
{.want = 0x4415AF1D78B58C40, .str = "1e20"},
{.want = 0x44B52D02C7E14AF6, .str = "1e23"},
{.want = 0x46293E5939A08CEA, .str = "1e30"},
{.want = 0x54B249AD2594C37D, .str = "+1E+100"},
{.want = 0x54B249AD2594C37D, .str = "+_1_E_+_1_0_0_"},
{.want = 0x7FEFFFFFFFFFFFFF, .str = "1.7976931348623157e308"},
{.want = 0x7FF0000000000000, .str = "1.8e308"},
{.want = 0x7FF0000000000000, .str = "1e+316"},
{.want = 0x7FF0000000000000,
.str = "10000000000000000000000000000000000000000000e+308"},
{.want = 0x7FF0000000000000, .str = "1e999"},
{.want = 0x7FF0000000000000, .str = "__InFinity__"},
{.want = 0x7FF0000000000000, .str = "inf"},
@@ -1321,6 +1328,15 @@ test_wuffs_strconv_render_number_f64() {
.want_3f = "9007199254740996.000",
.want_4g = "9.007e+15",
},
{
.x = 0x4370000000000000,
.want__e = "7.205759403792794e+16",
.want__f = "72057594037927940",
.want_0g = "7e+16",
.want_2e = "7.21e+16",
.want_3f = "72057594037927936.000",
.want_4g = "7.206e+16",
},
{
.x = 0x4415AF1D78B58C40,
.want__e = "1e+20",
@@ -1330,6 +1346,15 @@ test_wuffs_strconv_render_number_f64() {
.want_3f = "100000000000000000000.000",
.want_4g = "1e+20",
},
{
.x = 0x44B52D02C7E14AF6,
.want__e = "1e+23",
.want__f = "100000000000000000000000",
.want_0g = "1e+23",
.want_2e = "1.00e+23",
.want_3f = "99999999999999991611392.000",
.want_4g = "1e+23",
},
{
.x = 0x44DFC3842BD1F072,
.want__e = "6e+23",