Bug #70341 [Opn->Fbk]: Weird behaviour of memory_get and peak_usage

From: Date: Mon, 24 Aug 2015 20:00:41 +0000
Subject: Bug #70341 [Opn->Fbk]: Weird behaviour of memory_get and peak_usage
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195485@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70341&edit=1 ID: 70341 Updated by: cmb@php.net Reported by: quantuumsnot at gmail dot com Summary: Weird behaviour of memory_get and peak_usage -Status: Open +Status: Feedback Type: Bug Package: *General Issues Operating System: windows 7 x64 PHP Version: 7.0.0RC1 Block user comment: N Private report: N New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with , is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. See <https://3v4l.org/0SjGE> for expected behavior. Previous Comments: ------------------------------------------------------------------------ [2015-08-24 12:45:59] quantuumsnot at gmail dot com To be precise - using false gives me 0 bytes, using true gives me a rly big difference in bytes used ------------------------------------------------------------------------ [2015-08-24 12:42:08] quantuumsnot at gmail dot com Description: ------------ I usually use this short script to test some home-brew functions but noticed a inconsistency in memory_get_usage() and memory_get_peak_usage() Corresponding to docs, when using: FALSE parameter - emalloc() returns bytes used by the script TRUE parameter - returns bytes allocated by OS The problem is that the script worked on PHP 5.6.8 x64 Thread Safe - returned bytes are above 0, but in 7.0.0RC1 this returns 0 The fix is to use at line #1 memory_get_usage(false) which returns 40-50 times!!! bigger memory usage (for example 1.6-1.8MB instead of 40-45KB) Tested it on 3v4l.org and the results are the same, 5.5.0-5.6.12 always win What is the correct way to benchmark my code in PHP7 using pure PHP? (do not suggest xdebug or frameworks, please) Test script: --------------- $memoryUsage = memory_get_peak_usage(false); someFunctionCalled(); $memoryUsage = abs(memory_get_peak_usage(false) - $memoryUsage); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70341&edit=1

« previous php.bugs (#195485) next »