PHP String Compression Method Comparison Example _php tutorial

Source: Internet
Author: User
PHP provides a number of string compression methods, below for everyone to compare the next PHP string compression method, interested friends can refer to the next

PHP provides a string compression method with 1.gzcompress-compress A string this function Compress the given string using the ZLIB data format. 2.gzencode-create a gzip compressed string This function returns a compressed version of the input data compatible with The output of the GZIP program 3.gzdeflate-deflate a string This function compress the given string using the Deflate da TA format. 4.bzcompress-compresses a string into BZIP2 encoded data bzcompress () compresses the specified string and returns the data in BZIP2 encoding. The following compression comparison of these four methods, respectively, the Chinese and English digital compression copy code is as follows: Compress Chinese comparison

'; Compress_comp ($str 1, 1000); Compress 1000 times and unzip 1000 times compare Echo ' Comparison of compressed English numerals

'; Compress_comp ($str 2, 1000); Compress 1000 times with decompression 1000 comparison/* compression */function Compress_comp ($STR, $num) {$func _compress = array (' gzcompress ', ' gzencode ', ' Gzd Eflate ', ' bzcompress '); Echo ' original: '. $str. '

'; Echo ' Original size: '. strlen ($str). '

'; For ($i =0, $length =count ($func _compress), $i < $length, $i + +) {$starttime = Get_microtime (); for ($j =0; $j < $num; $j + +) {switch ($func _compress[$i]) {case ' gzcompress ': $mstr = gzcompress ($str, 9);//Decompression method: Gzuncompress break; case ' Gzencode ' : $mstr = Gzencode ($str, 9); Decompression method: Gzdecode php>=5.4 break; Case ' gzdeflate ': $mstr = Gzdeflate ($str, 9); Decompression method: Gzinflate break; Case ' bzcompress ': $mstr = bzcompress ($str, 9); Decompression method: Bzdecompress break; }} $endtime = Get_microtime (); echo $func _compress[$i]. ' Compressed size: ' strlen ($mstr). ' Time-consuming: '. Round (($endtime-$starttime) *1000,5). ' Ms

'; }/* Get Microtime */function Get_microtime () {list ($usec, $sec) = Explode (", microtime (True)); return $usec + $sec;}? > execution Result: Copy code code as follows: Compress Chinese comparison original: Layout 1 describes the layout, simply to set the size and position of the element. EXT's layout system consists of components, layouts, containers, and containers that are a special component that can manage the size and position of the component. The container is dolayout to recalculate the layout and update the DOM. 2 manual layout is unnecessary, and the framework automatically handles it for you. Original size: 328 gzcompress Compressed Size: 251 time: 59.99994ms gzencode Compressed Size: 263 time: 120.00012ms gzdeflate Compressed Size: 245 Time: 119.99989ms Bzcompress Compressed Size: 303 time: 259.99999ms compressed English numerals comparison original:!@#$%^&* () qwertyuiopsdfghjkl!@#$%^&* () QWERTYUIOPSDFGHJKL: zxcvbnma!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopd:zxcvbnm#!@#!@#$%^&* () QWERTYUIOPSDFGHJKL: zxcvbnm-!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopd$%^&* () ertyuiodfghj!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnm]!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopdklxcvbnm@#$%^&* () Rtyuiopdfghjklcvbnmfghjtyu%^&rfghj4d56g7h8ui7h8ujirqwerqh8 Original size: 386 gzcompress Compressed Size: 116 Time: 50.00019ms Gzencode Compressed size: 128 Time: 99.9999MS gzdeflate Compressed Size: 110 Time: 89.99991ms bzcomPress Compressed Size: 183 Time: 210.00004ms can be obtained gzcompress the fastest, high compression ratio. Gzdeflate Compression ratio is the highest, the speed is slightly slower than gzcompress Gzencode and gzdeflate closer, gzdeflate a slight advantage bzcompress speed slowest, the compression ratio is the slowest. It is therefore recommended to use gzcompress and gzdeflate.

http://www.bkjia.com/PHPjc/727560.html www.bkjia.com true http://www.bkjia.com/PHPjc/727560.html techarticle PHP provides a number of string compression methods, below for everyone to compare the PHP string compression method, interested friends can refer to the following PHP string compression method has 1.gzcompress ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.