Php string compression method comparison example _ PHP Tutorial

Source: Internet
Author: User
Php string compression method comparison example. There are many string compression methods provided by compress php. The following describes the php string compression methods. if you are interested, refer

Php provides the following string compression methods: 1.gz compress-Compress a string This function compress the given string using the ZLIB data format. 2.gz encode-Create a gzip compressed string This function returns a compressed version of the input data compatible with the output of the gzip program 3.gz deflate-Deflate a string This function compress the given string using DEFLATE data format. 4. bzcompress-compress a string into bzip 2. the encoded data bzcompress () compresses the specified string and returns data in bzip2 encoding. The following code compresses and compares Chinese and English numbers in the following four methods: Compressed Chinese comparison

'; Compress_comp ($ str1, 1000); // compress 1000 times and decompress 1000 times to compare echo' Compress English numbers

'; Compress_comp ($ str2, 1000); // compress 1000 times and decompress 1000 times/* compress */function compress_comp ($ str, $ num) {$ func_compress = array ('gzcompress ', 'gzencode', 'gzdeflate', 'bzcompress'); echo 'original :'. $ str.'

'; Echo 'original Text 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]. 'Size after compression :'. strlen ($ mstr ). 'Time consumed :'. round ($ endtime-$ starttime ). 'Ms

';}}/* Get microtime */function get_microtime () {list ($ usec, $ sec) = explode ('', microtime (true )); return $ usec + $ sec;}?> Execution result: the code is as follows: compress the Chinese text to compare the original text: Layout 1 introduces the layout. Simply put, it is to set the size and position of the element. The layout system of Ext includes components, layout, containers, and containers. it is a special component that allows you to manage the size and position of components. The container recalculates the layout through doLayout and updates the DOM. 2 manual layout. The framework will automatically process the layout for you. Original article size: 328 size after gzcompress compression: 251 elapsed time: 59.99994 ms after gzencode compression size: 263 elapsed time: 120.00012 ms after gzdeflate compression size: 245 elapsed time: 119.99989 ms bzcompress after compression size: 303 time consumption: 259.99999 ms compression English numbers comparison original :! @ # $ % ^ & * () QWERTYUIOPSDFGHJKL! @ # $ % ^ & * () QWERTYUIOPSDFGHJKL: ZXCVBNMa! @ # $ % ^ & * () ERTYUIODFGHJKLXCVBNM @ # $ % ^ & * () RTYUIOPD: ZXCVBNM #! @#! @ # $ % ^ & * () QWERTYUIOPSDFGHJKL: ZXCVBNM -! @ # $ % ^ & * () ERTYUIODFGHJKLXCVBNM @ # $ % ^ & * () RTYUIOPD $ % ^ & * () ERTYUIODFGHJ! @ # $ % ^ & * () QWERTYUIOPSDFGHJKL: ZXCVBNM]! @ # $ % ^ & * () ERTYUIODFGHJKLXCVBNM @ # $ % ^ & * () RTYUIOPDKLXCVBNM @ # $ % ^ & * () rtyuio1_ghjklcvbnmfghjtyu % ^ & proportion original size: 386 size after gzcompress compression: 116 elapsed time: 50.00019 ms after gzencode compression size: 128 elapsed time: 99.9999 ms after gzdeflate compression size: 110 elapsed time: 89.99991 ms after bzcompress compression size: 183 elapsed time: 210.00004 ms, it can be concluded that gzcompress is the fastest and the compression ratio is high. The gzdeflate compression ratio is the highest, and the speed is slightly slower than that of gzcompress gzencode and gzdeflate. gzdeflate has a slight advantage: bzcompress is the slowest, and the compression ratio is the slowest. Therefore, we recommend that you use gzcompress and gzdeflate.

The string compression method provided by the http://www.bkjia.com/PHPjc/727560.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/727560.htmlTechArticlephp has a lot, below for everyone to compare php string compression method, interested friends can refer to the next php character strings compressed character 1.gz compress...

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.