定制 serafim/packed-array 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

serafim/packed-array

Composer 安装命令:

composer require serafim/packed-array

包简介

Typed arrays with reduced memory consumption

README 文档

README

PHP 8.1+ Latest Stable Version Latest Unstable Version Total Downloads License MIT

Introduction

PHP packed (typed) arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers with reduced memory consumption on large amounts of data.

Common PHP arrays grow and shrink dynamically and can have any value. PHP Zend VM perform optimizations so that these arrays are fast. However, in some cases, the standard functionality is not enough and the standard PHP array can take up a very large amount of data, for example, when working with audio, image and video. This is where typed arrays come in. Each entry in a PHP typed array is a raw binary value in one of a number of supported formats, from 8-bit integers to 64-bit floating-point numbers.

For example, an image with a size of 44.968Kb, when loaded into a typed array, takes 45.168Kb of memory. However, if it is unpacked into a native PHP array, then the size of such an image in memory will take 5,633.360Kb. That is more than 120 times!

Below is a graph of the size of the consumed RAM depending on the size of the array (number of elements).

/resources/memory-usage.png

See the bin/memory-usage.php for details on how the this RAM consumption was calculated.

Read/Write

Please note that such arrays are designed to store a large amount of data, however, they are noticeably slower than those builtin PHP arrays during reading and writing.

Reading

subject revs its mem_peak mode rstdev
benchNative 10000 5 1.291mb 0.018μs ±1.83%
benchSplFixedArray 10000 5 1.291mb 0.028μs ±3.06%
benchPackedInt8 10000 5 1.291mb 0.087μs ±1.37%
benchPackedUInt8 10000 5 1.291mb 0.079μs ±1.65%
benchPackedInt16 10000 5 1.291mb 0.104μs ±1.12%
benchPackedUInt16 10000 5 1.291mb 0.108μs ±10.24%
benchPackedInt32 10000 5 1.291mb 0.159μs ±1.06%
benchPackedUInt32 10000 5 1.291mb 0.174μs ±0.98%
benchPackedInt64 10000 5 1.291mb 0.160μs ±0.55%
benchPackedFloat32 10000 5 1.291mb 1.225μs ±1.46%
benchPackedFloat64 10000 5 1.291mb 1.232μs ±1.33%

Writing

subject revs its mem_peak mode rstdev
benchNative 10000 5 1.291mb 0.019μs ±2.52%
benchSplFixedArray 10000 5 1.291mb 0.032μs ±2.10%
benchPackedInt8 10000 5 1.291mb 0.088μs ±2.45%
benchPackedUInt8 10000 5 1.291mb 0.089μs ±0.50%
benchPackedInt16 10000 5 1.291mb 0.108μs ±1.42%
benchPackedUInt16 10000 5 1.291mb 0.121μs ±4.27%
benchPackedInt32 10000 5 1.291mb 0.146μs ±1.49%
benchPackedUInt32 10000 5 1.291mb 0.153μs ±1.62%
benchPackedInt64 10000 5 1.291mb 0.220μs ±1.79%
benchPackedFloat32 10000 5 1.291mb 1.268μs ±0.91%
benchPackedFloat64 10000 5 1.291mb 1.343μs ±0.44%

Installation

This library is available as Composer repository and can be installed using the following command in a root of your project:

$ composer require serafim/packed-array

Quick Start

TODO

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固