Yaconf 1.1.0 - 40%速度提升版

栏目: IT技术 · 发布时间: 5年前

内容简介:Yaconf是一个高性能的PHP配置容器, 它在PHP启动的时候把格式为INI的配置文件Parse后存储在PHP的常驻内存中,不需要每次请求的时候都来分析配置文件,并且在获取配置项的时候"zero-copy",具体的介绍可以看我2015年发布的时候写的介绍:Yaconf在微博被大量使用,也稳定运行了这么多年,但是2015年发布后基本也没有什么大的变化。最近因为疫情,我对Yaconf做了一系列的重构,主要是减少取过程中的内存使用,基本重写了整体的逻辑,那性能优化的结果如何呢? 我们来做个简单的测试。

Yaconf是一个高性能的 PHP 配置容器, 它在PHP启动的时候把格式为INI的配置文件Parse后存储在PHP的常驻内存中,不需要每次请求的时候都来分析配置文件,并且在获取配置项的时候"zero-copy",具体的介绍可以看我2015年发布的时候写的介绍: Yaconf - 一个高性能的配置管理扩展

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!


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms

Algorithms

Robert Sedgewick、Kevin Wayne / Addison-Wesley Professional / 2011-3-19 / USD 89.99

Essential Information about Algorithms and Data Structures A Classic Reference The latest version of Sedgewick,s best-selling series, reflecting an indispensable body of knowledge developed over the ......一起来看看 《Algorithms》 这本书的介绍吧!

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具