示例工程 24-performance
24-performance/03-prealloc-table/README.md
# 03 · prealloc-table
**演示**:`t[#t+1]=v` 与 `t[i]=v` 填 5 万元素。
**运行时**:`lua54`、`luajit`。
**运行**:
```sh
.tools/bin/lua54 scripts/run-example.lua examples/24-performance/03-prealloc-table
.tools/bin/lua54 scripts/test-example.lua examples/24-performance/03-prealloc-table
```
**预期输出**(lua 5.4.9 / macOS arm64;耗时随机器变化):
```text
same_length=true prealloc_faster=true
```
**看点**:按索引赋值避免每次取 `#t`,也减少扩容检查。
**注意**:差异是常数级,先测量再重构。