This is an old revision of the document!
Request for Comments: How to write RFCs
- Version: 1.0
- Date: 2011-07-15
- Author: David Soria Parra <dsp at php dot net>
- Status: Under Discussion
- Proposed for: PHP 5.4
Introduction
Converting strings to doubles is a common problem in applications. The current standard in solving this problem is David Gays strtod algorithm. This algorithm is used in PHP and can be found in zend_strtod. Recently Florian Loitsch found a new algorithm, called grisu3, to this problem. His algorithm is faster than David Gays algorithm. An OpenSource implementation exists here.
Proposal
- add grisu3 library to PHP source
- add grisu3 to the PHP build system
- add --enable-grisu3 option to PHP configure. disabled by default.
Why do we need a new strtod?
Using grisu3 will speed up string to double and double to string conversions. In particular json_encode and json_decode of json data includign doubles will be faster. Simple microbenchmarks show about 30% faster json_decode.
Common Misconceptions
The grisu3 algorithm is optional. By default we still use David Gays algorithm. There is no BC break in the API.
Caveats
The double-conversion library is written in C++. To compile PHP with grisu3 you will need a C++ compiler.
Proposal and Patch
There is a initial patchset at http://bitbucket.org/segv/php-src