PHP7扩展开发-FAST_ZPP

  PHP内部函数使用 zend_parse_parameters() API 接受参数,将输入参数转换成c变量,这个函数使用类似scanf()函数的参数解释方法,通过一个字符串来定义输入参数的个数和类型,例如(“s” - for string, “l” for long),不幸的是,每次调用这个函数时都要对这个这个字符串进行解析,这会加重性能开销。

  例如,在一下wordpress的首页,zend_parse_parameters()函数占用6%的cpu运行时间,在一些简单的函数 is_string() 或者 ord() zend_parse_parameters() 几乎占用将近90%的开销。

zend_parse_parameters()参数说明:
第一个参数,参数个数。一般就使用ZEND_NUM_ARGS(),不需要改变。
第二个参数,格式化字符串。这个格式化字符串的作用就是,指定传入参数与PHP内核类型的转换关系。

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
    return;
}

FAST ZPP

在PHP7中新提供的方式。是为了提高参数解析的性能。对应经常使用的方法,建议使用FAST ZPP方式。
使用方式:
以ZEND_PARSE_PARAMETERS_START(1, 2)开头。
第一个参数表示必传的参数个数,第二个参数表示最多传入的参数个数。
以ZEND_PARSE_PARAMETERS_END();结束。
中间是传入参数的解析。

ZEND_PARSE_PARAMETERS_START(2, 4)
    Z_PARAM_ARRAY(input)
    Z_PARAM_LONG(offset)
    Z_PARAM_OPTIONAL
    Z_PARAM_ZVAL(z_length)
    Z_PARAM_BOOL(preserve_keys)
ZEND_PARSE_PARAMETERS_END();

新API涵盖了现有API的所有可能性。下表显示了老说明符和新宏之间的对应关系。

specifier   Fast ZPP API macro  args
|   Z_PARAM_OPTIONAL
a   Z_PARAM_ARRAY(dest) dest - zval*
A   Z_PARAM_ARRAY_OR_OBJECT(dest)   dest - zval*
b   Z_PARAM_BOOL(dest)  dest - zend_bool
C   Z_PARAM_CLASS(dest) dest - zend_class_entry*
d   Z_PARAM_DOUBLE(dest)    dest - double
f   Z_PARAM_FUNC(fci, fcc)  fci - zend_fcall_info, fcc - zend_fcall_info_cache
h   Z_PARAM_ARRAY_HT(dest)  dest - HashTable*
H   Z_PARAM_ARRAY_OR_OBJECT_HT(dest)    dest - HashTable*
l   Z_PARAM_LONG(dest)  dest - long
L   Z_PARAM_STRICT_LONG(dest)   dest - long
o   Z_PARAM_OBJECT(dest)    dest - zval*
O   Z_PARAM_OBJECT_OF_CLASS(dest, ce)   dest - zval*
p   Z_PARAM_PATH(dest, dest_len)    dest - char*, dest_len - int
P   Z_PARAM_PATH_STR(dest)  dest - zend_string*
r   Z_PARAM_RESOURCE(dest)  dest - zval*
s   Z_PARAM_STRING(dest, dest_len)  dest - char*, dest_len - int
S   Z_PARAM_STR(dest)   dest - zend_string*
z   Z_PARAM_ZVAL(dest)  dest - zval*
    Z_PARAM_ZVAL_DEREF(dest)    dest - zval*
+   Z_PARAM_VARIADIC('+', dest, num)    dest - zval*, num int
*   Z_PARAM_VARIADIC('*', dest, num)    dest - zval*, num int

参考:

https://wiki.php.net/rfc/fast_zpp
https://yq.aliyun.com/articles/69523?spm=5176.8091938.0.0.g3PyCC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C:\Users\TXN>CD C:// C:\>Python "C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\demos\human_pose_estimation_demo\python\human_pose_estimation_demo.py" -at openpose -d CPU -i 0 -m D:\model\fall_detection_zpp\intel\human-pose-estimation-0001\FP16\human-pose-estimation-0001.xml [ INFO ] Initializing Inference Engine... [ INFO ] Loading network... [ INFO ] Reading network from IR... Traceback (most recent call last): File "C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\demos\human_pose_estimation_demo\python\human_pose_estimation_demo.py", line 283, in <module> sys.exit(main() or 0) File "C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\demos\human_pose_estimation_demo\python\human_pose_estimation_demo.py", line 184, in main model = get_model(ie, args, frame.shape[1] / frame.shape[0]) File "C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\demos\human_pose_estimation_demo\python\human_pose_estimation_demo.py", line 111, in get_model prob_threshold=args.prob_threshold) File "C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\demos\common\python\models\open_pose.py", line 62, in __init__ strides=(1, 1), name=self.pooled_heatmaps_blob_name) File "C:\Users\TXN\AppData\Local\Programs\Python\Python37\lib\site-packages\ngraph\utils\decorators.py", line 22, in wrapper node = node_factory_function(*args, **kwargs) TypeError: max_pool() missing 1 required positional argument: 'dilations'
最新发布
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值