1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext
Tim Düsterhus 2c5ed50d5c zend_compile: Add support for %d to sprintf() optimization (#14561)
* zend_compile: Rename `string_placeholder_count` to `placeholder_count` in `zend_compile_func_sprintf()`

This is intended to make the diff of a follow-up commit smaller.

* zend_compile: Add support for `%d` to `sprintf()` optimization

This extends the existing `sprintf()` optimization by support for the `%d`
placeholder, which effectively equivalent to an `(int)` cast followed by a
`(string)` cast.

For a synthetic test using:

    <?php

    $a = 'foo';
    $b = 42;

    for ($i = 0; $i < 100_000_000; $i++) {
        sprintf("%s-%d", $a, $b);
    }

This optimization yields a 1.3× performance improvement:

    $ hyperfine 'sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php' \
          '/tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php'
    Benchmark 1: sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php
      Time (mean ± σ):      3.296 s ±  0.094 s    [User: 3.287 s, System: 0.005 s]
      Range (min … max):    3.213 s …  3.527 s    10 runs

    Benchmark 2: /tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php
      Time (mean ± σ):      4.300 s ±  0.025 s    [User: 4.290 s, System: 0.007 s]
      Range (min … max):    4.266 s …  4.334 s    10 runs

    Summary
      sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php ran
        1.30 ± 0.04 times faster than /tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php

* Fix sprintf_rope_optimization_003.phpt test expecation for 32-bit integers

* zend_compile: Indent switch-case labels in zend_compile_func_sprintf()

* Add GMP test to sprintf() rope optimization

* Add `%s` test case to sprintf() GMP test
2024-06-17 17:07:50 +02:00
..
2024-06-08 17:15:36 +01:00
2024-06-09 14:23:41 +02:00
2024-06-09 14:23:41 +02:00
2024-06-08 17:15:36 +01:00
2024-06-08 17:15:36 +01:00
2024-06-11 22:47:05 +02:00
2024-06-08 17:15:36 +01:00
2024-06-01 17:12:42 +01:00
2024-06-11 22:47:05 +02:00
2024-06-17 09:38:17 +03:00
2024-06-17 13:02:53 +02:00
2024-06-08 17:15:36 +01:00
2024-06-04 12:51:06 -03:00
2024-06-11 22:47:05 +02:00
2024-06-10 22:58:25 +02:00
2024-06-08 17:15:36 +01:00
2024-06-16 23:01:52 +01:00
2024-06-08 17:15:36 +01:00
2024-06-08 17:15:36 +01:00
2024-06-15 14:42:27 +02:00
2024-06-08 17:15:36 +01:00
2024-06-01 17:12:42 +01:00