Yaconf在微博被大量使用,也稳定运行了这么多年,但是2015年发布后基本也没有什么大的变化。
最近因为疫情,我对Yaconf做了一系列的重构,主要是减少取过程中的内存使用,基本重写了整体的逻辑,那性能优化的结果如何呢? 我们来做个简单的测试。
首先测试配置文件如下:
name="yaconf"
version="1.1.0"
[author]
name="Laruence"
blog.address="https://www.laruence.com"
[developer : author]
projects.yaf.repo="https://github.com/laruence/yaf"测试脚本如下:
<?php
function bench($key) {
$count = 1000000;
$start = microtime(true);
while ($count--) {
Yaconf::get($key);
}
printf("%s: %fs\n", $key, microtime(true) - $start);
}
bench("config.name");
bench("config.author.name");
bench("config.author.blog.address");
bench("config.developer.projects.yaf.repo");
?>首先我们用yaconf-1.0.8来测试:
config.name: 0.129616s
config.author.name: 0.172129s
config.author.blog.address: 0.206659s
config.developer.projects.yaf.repo: 0.248205s然后我们来用yaconf-1.1.0测试下:
config.name: 0.075837s
config.author.name: 0.098553s
config.author.blog.address: 0.144033s
config.developer.projects.yaf.repo: 0.144580s可以看到获取配置平均能有40%的耗时减少,尤其当你使用链式方法获取配置内容的时候,越长提升越明显。
好了, Yaconf-1.1.0已经发布到PECL: Yaconf
enjoy!