Skip to content

Commit ced2ebb

Browse files
committed
docs(readme): update documentation with self-hosting details and benchmark data --skip-tests
1 parent 7973f99 commit ced2ebb

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ env:
1919
jobs:
2020
build-phpx:
2121
name: Build PHPX (PHP ${{ matrix.php }})
22+
# Skip the whole test pipeline when the push commit message contains `--skip-tests`.
23+
if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }}
2224
runs-on: ubuntu-latest
2325
timeout-minutes: 30
2426
strategy:
@@ -94,6 +96,7 @@ jobs:
9496

9597
phpunit:
9698
name: PHPUnit (PHP ${{ matrix.php }})
99+
if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }}
97100
runs-on: ubuntu-latest
98101
timeout-minutes: 30
99102
needs: build-phpx
@@ -158,6 +161,7 @@ jobs:
158161

159162
phpt:
160163
name: PHPT (PHP ${{ matrix.php }})
164+
if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }}
161165
runs-on: ubuntu-latest
162166
timeout-minutes: 180
163167
needs: build-phpx

README-CN.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ TypePHP 是一个 AOT(Ahead-Of-Time,提前编译)编译器,它把 PHP
2222
它保留熟悉的 PHP 语法,同时引入编译期类型信息,让编译器为你的性能热点生成快速、
2323
静态类型的 C++ 代码,而其余代码仍运行在久经考验的 Zend 引擎上。
2424

25+
TypePHP **完全由 PHP 语言编写**,并且**完全自举**`tpc` 编译器二进制就是
26+
用 TypePHP 编译编译器自身的 PHP 源码得到的。整个自举链路是纯 PHP——编译器
27+
本身没有任何 C 或 C++ 胶水代码。
28+
2529
## 特性
2630

31+
- **完全自举、纯 PHP 实现** —— TypePHP 编译器完全由 PHP 语言编写,并能自举:
32+
`tpc` 编译编译器自身的源码,即可生成原生二进制。
2733
- **真正的 AOT 编译** —— PHP 先降级为 C++17,再编译为原生机器码。无解释器、
2834
无 opcode 缓存、无 JIT 预热。
2935
- **三种构建模式** —— 同一份代码可编译为独立 `bin` 可执行文件、可加载的 PHP
@@ -74,20 +80,21 @@ TypePHP 是一个 AOT(Ahead-Of-Time,提前编译)编译器,它把 PHP
7480
- **PHP 8.4 – 8.5**,需包含 `embed` 模块(`libphp.so`
7581
- **GCC 9+**(或 Clang),支持 **C++17**
7682
- **CMake 3.24+**
77-
- 高精度数学库:**GMP****MPFR****libmpdec**
83+
- 高精度数学库:**GMP****MPFR**libmpdec 已随 PHPX 内置)
7884

7985
```shell
8086
# Ubuntu/Debian
81-
sudo apt install libgmp-dev libmpfr-dev libmpdec-dev
87+
sudo apt install libgmp-dev libmpfr-dev
8288

8389
# RHEL/CentOS/Fedora
84-
sudo dnf install gmp-devel mpfr-devel libmpdec-devel
90+
sudo dnf install gmp-devel mpfr-devel
8591

8692
# Arch Linux
87-
sudo pacman -S gmp mpfr mpdecimal
93+
sudo pacman -S gmp mpfr
8894
```
8995

90-
> GMP 用于 `bigInt`,MPFR 用于 `bigFloat`,libmpdec 用于 `decimal`
96+
> GMP 用于 `bigInt`,MPFR 用于 `bigFloat``decimal` 底层是 libmpdec,
97+
> 已随 PHPX 内置,无需单独安装。
9198
9299
预览版目前以 **Linux** 为主要开发平台(推荐 Ubuntu 22.04)。Windows 和 macOS
93100
打包通过同一入口点支持。
@@ -322,6 +329,21 @@ function main(): void
322329

323330
## 基准测试
324331

332+
### PHP 语言基准(来自 php-src)
333+
334+
TypePHP 使用 `-O3` 运行 PHP 源码树自带的官方 `bench.php`
335+
`micro_bench.php` 语言性能测试:
336+
337+
| 基准 | 解释执行 PHP | TypePHP AOT(`-O3`| 加速比 |
338+
|---|---|---|---|
339+
| `bench.php`(总计) | 5.034 秒 | **0.603 秒** | 约 8× |
340+
| `micro_bench.php`(总计) | 13.045 秒 | **2.021 秒** | 约 6.5× |
341+
342+
两项基准覆盖 PHP 语言核心性能——函数调用、对象属性访问、数组/哈希访问、
343+
字符串处理、控制流等。完整逐项报告见 [`bench.txt`](bench.txt)
344+
345+
### std::array 对比 PHP 数组
346+
325347
一个 10000×100000 的元素累加循环,对比 PHP 数组、TypePHP `std::array`
326348
与原生 C++:
327349

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ It keeps familiar PHP syntax and adds compile-time type information, so the
2525
compiler can emit fast, statically-typed C++ for your hot paths — while the
2626
rest of your code continues to run on the battle-tested Zend engine.
2727

28+
TypePHP is **written entirely in PHP** and is **fully self-hosting**: the `tpc`
29+
compiler binary is built by compiling the compiler's own PHP source code with
30+
TypePHP. The bootstrap chain is pure PHP — no C or C++ glue in the compiler
31+
itself.
32+
2833
## Features
2934

35+
- **Self-hosting, written in PHP** — the TypePHP compiler is implemented
36+
entirely in PHP and bootstraps itself: `tpc` compiles the compiler's own
37+
source into a native binary.
3038
- **True AOT compilation** — PHP is lowered to C++17, then to native machine
3139
code. No interpreter, no opcode cache, no JIT warm-up.
3240
- **Three build modes** — build a standalone `bin` executable, a loadable PHP
@@ -87,20 +95,21 @@ rest of your code continues to run on the battle-tested Zend engine.
8795
- **PHP 8.4 – 8.5** with the `embed` module (`libphp.so`)
8896
- **GCC 9+** (or Clang) with **C++17**
8997
- **CMake 3.24+**
90-
- High-precision math libraries: **GMP**, **MPFR**, **libmpdec**
98+
- High-precision math libraries: **GMP**, **MPFR** (libmpdec is bundled with PHPX)
9199

92100
```shell
93101
# Ubuntu/Debian
94-
sudo apt install libgmp-dev libmpfr-dev libmpdec-dev
102+
sudo apt install libgmp-dev libmpfr-dev
95103

96104
# RHEL/CentOS/Fedora
97-
sudo dnf install gmp-devel mpfr-devel libmpdec-devel
105+
sudo dnf install gmp-devel mpfr-devel
98106

99107
# Arch Linux
100-
sudo pacman -S gmp mpfr mpdecimal
108+
sudo pacman -S gmp mpfr
101109
```
102110

103-
> GMP powers `bigInt`, MPFR powers `bigFloat`, and libmpdec powers `decimal`.
111+
> GMP powers `bigInt` and MPFR powers `bigFloat`. The `decimal` type is backed
112+
> by libmpdec, which is bundled with PHPX — no separate install required.
104113
105114
The preview currently targets **Linux** as the primary development platform
106115
(Ubuntu 22.04 recommended). Windows and macOS packaging is supported through
@@ -340,6 +349,22 @@ See [Mixed C++/PHP](docs/MIXED_CPP_PHP.md).
340349

341350
## Benchmark
342351

352+
### PHP language benchmarks (from php-src)
353+
354+
TypePHP runs the official `bench.php` and `micro_bench.php` language
355+
benchmarks that ship with the PHP source tree, compiled with `-O3`:
356+
357+
| Benchmark | Interpreted PHP | TypePHP AOT (`-O3`) | Speedup |
358+
|---|---|---|---|
359+
| `bench.php` (total) | 5.034 s | **0.603 s** | ~|
360+
| `micro_bench.php` (total) | 13.045 s | **2.021 s** | ~6.5× |
361+
362+
Both benchmarks measure core PHP language performance — function calls, object
363+
property access, array/hash access, string handling, control flow, and more.
364+
See the full per-item report in [`bench.txt`](bench.txt).
365+
366+
### std::array vs PHP array
367+
343368
A 10000×100000 element update loop, comparing PHP arrays against TypePHP's
344369
`std::array` and native C++:
345370

0 commit comments

Comments
 (0)