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

From: Date: Thu, 27 Aug 2015 10:17:56 +0000
Subject: Bug #70341 [Fbk]: Weird behaviour of memory_get and peak_usage
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195550@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:             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:

You have claimed

> 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)

and later corrected

> using false gives me 0 bytes, using true gives me a rly big
> difference in bytes used

However, <https://3v4l.org/COXWa> doesn't show this
behavior.


Previous Comments:
------------------------------------------------------------------------
[2015-08-27 01:44:27] quantuumsnot at gmail dot com

https://3v4l.org/COXWa

------------------------------------------------------------------------
[2015-08-26 20:50:47] cmb@php.net

> Tested it on 3v4l.org and the results are the same, 5.5.0-5.6.12 always win

Can you please post a link to the 3v4l.org test?

------------------------------------------------------------------------
[2015-08-26 20:34:24] quantuumsnot at gmail dot com

This problem is valid for devster's 'Ubench' script too:
---
<?php

error_reporting(-1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
gc_enable();

// https://github.com/devster/ubench
require_once 'src/Ubench.php';

$bench = new Ubench;
$testSum = 0;
$bench->start();
// Execute some code
for ($i = 0; $i < 1000000; $i++) { $j= $i; }
$bench->end();

// Get elapsed time and memory
echo "<br />" . $bench->getTime();
echo "<br />" . $bench->getTime(true); // elapsed microtime in float
echo "<br />" . $bench->getTime(false, '%d%s');

echo "<br />" . $bench->getMemoryPeak();
echo "<br />" . $bench->getMemoryPeak(true); // memory peak in bytes
echo "<br />" . $bench->getMemoryPeak(false, '%.3f%s');

// Returns the memory usage at the end mark
echo "<br />" . $bench->getMemoryUsage();

exit();

?>

------------------------------------------------------------------------
[2015-08-24 20:00:36] cmb@php.net

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.

------------------------------------------------------------------------
[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

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=70341


--
Edit this bug report at https://bugs.php.net/bug.php?id=70341&edit=1


Thread (10 messages)

« previous php.bugs (#195550) next »