# zend_u_strtod is slow - possible fix

- Thread: https://externals.io/message/25072
- Original archive: https://news-web.php.net/php.internals/25072
- Started by Matt W on 2006-07-31T08:58:30+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #25072 — Matt W — 2006-07-31T08:58:30+00:00

URL: https://externals.io/message/25072#25072

Hi all,

As I was working on upgrading the dec[bin|hex|oct] functions to convert
large doubles, I noticed how much slower things were when converting Unicode
strings to double.  I found that converting the whole thing to string and
using regular zend_strtod() was much faster.  Then I decided to try
modifying the u_strtod() function to do the same, but just on the relevant
numeric portion.

I don't know if I did everything right, but it seems to work fine with my
limited testing.  (I was working from zend_u_strtol() and
zval_unicode_to_string_ex(). :-))  The function is now about *8 times*
faster, and nearly 20 times faster on a non-numeric string!  (I'm on
Windows.)

diff: http://realplain.com/php/zend_u_strtod.diff

Is this something that can be used?


Thanks,
Matt

---

## #25082 — Andrei Zmievski — 2006-08-01T18:02:36+00:00

URL: https://externals.io/message/25072#25082 · In reply to: #25072

Yes. With your patch applied, the numeric unicode string to double 
conversion is about 100% slower than from binary strings. If this is 
acceptable we can commit the patch. Otherwise, we should port 
zend_strtod() to deal with unicode strings directly.

-Andrei



> Hi all,
>
> As I was working on upgrading the dec[bin|hex|oct] functions to convert
> large doubles, I noticed how much slower things were when converting 
> Unicode
> strings to double.  I found that converting the whole thing to string 
> and
> using regular zend_strtod() was much faster.  Then I decided to try
> modifying the u_strtod() function to do the same, but just on the 
> relevant
> numeric portion.
>
> I don't know if I did everything right, but it seems to work fine with 
> my
> limited testing.  (I was working from zend_u_strtol() and
> zval_unicode_to_string_ex(). :-))  The function is now about *8 times*
> faster, and nearly 20 times faster on a non-numeric string!  (I'm on
> Windows.)
>
> diff: http://realplain.com/php/zend_u_strtod.diff
>
> Is this something that can be used?
>
>
> Thanks,
> Matt

---

## #25106 — Matt W — 2006-08-02T09:12:52+00:00

URL: https://externals.io/message/25072#25106 · In reply to: #25082

Hi Andrei,

Thanks for your reply.  Yeah, obviously it'll still be slower than with an
already-binary string. :-)  But I figured it's better than before, until
something better comes along...

Unless there were other plans to rewrite it, is there a way to easily (for
me! :-)) have it do all the conversion?  I've been thinking about the
different string-to-number functions (will send a separate e-mail)...  Is
there a reason the regular zend_strtod() code is so complicated?
zend_string_to_double(), for example, is really simple (and works the same I
assume, except for not handling negatives or leading whitespace).  Can
zend_u_strtod() be implemented with the same methods zend_string_to_double()
uses?


Thanks,
Matt


----- Original Message -----
From: "Andrei Zmievski"
Sent: Tuesday, August 01, 2006


> Yes. With your patch applied, the numeric unicode string to double
> conversion is about 100% slower than from binary strings. If this is
> acceptable we can commit the patch. Otherwise, we should port
> zend_strtod() to deal with unicode strings directly.
>
> -Andrei
>
> 
>
> > […]

---

## #25136 — Andrei Zmievski — 2006-08-02T16:23:26+00:00

URL: https://externals.io/message/25072#25136 · In reply to: #25106

You'd have to ask Derick. He's the one who added it. :) Note that 
zend_string_to_double() is not actually used anywhere.

-A



> Hi Andrei,
>
> Thanks for your reply.  Yeah, obviously it'll still be slower than 
> with an
> already-binary string. :-)  But I figured it's better than before, 
> until
> something better comes along...
>
> Unless there were other plans to rewrite it, is there a way to easily 
> (for
> me! :-)) have it do all the conversion?  I've been thinking about the
> different string-to-number functions (will send a separate e-mail)...  
> Is
> there a reason the regular zend_strtod() code is so complicated?
> zend_string_to_double(), for example, is really simple (and works the 
> same I
> assume, except for not handling negatives or leading whitespace).  Can
> zend_u_strtod() be implemented with the same methods 
> zend_string_to_double()
> uses?

---

## #25161 — Derick Rethans — 2006-08-03T07:24:10+00:00

URL: https://externals.io/message/25072#25161 · In reply to: #25136

> You'd have to ask Derick. He's the one who added it. :) Note that
> zend_string_to_double() is not actually used anywhere.

I stole it from BSD, and yes... this is really needed because of all the 
different architectures.

Derick

---

## #25192 — Andrei Zmievski — 2006-08-03T16:13:13+00:00

URL: https://externals.io/message/25072#25192 · In reply to: #25161

Want to port it to support UChar*?

-A



> 
>
> > […]
>
> I stole it from BSD, and yes... this is really needed because of all 
> the
> different architectures.
>
> Derick
