Skip to content

Correct memory usage estimation in range() documentation #4680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rururu3
Copy link

@rururu3 rururu3 commented May 16, 2025

Hello,
I found that the PHP manual states that executing range(0, 1000000) uses more than 100MB of memory (link to the documentation). However, when I tested it, the actual memory usage was around 18MB, which is significantly lower than the documented value.
Here is the test script I used:

<?php
    // Memory usage before execution
    $memoryUsageBefore = memory_get_usage(true) / 1024 / 1024;
    echo "Used memory before process: " . $memoryUsageBefore . " MB" . PHP_EOL;

    $arr = range(0, 1000000);

    // Memory usage after execution
    $memoryUsageAfter = memory_get_usage(true) / 1024 / 1024;
    echo "Used memory after process: " . $memoryUsageAfter . " MB" . PHP_EOL;

Given this discrepancy, I suggest updating the documentation to reflect a more accurate memory usage estimate (e.g., 10MB instead of 100MB).
Please let me know if further testing or clarification is needed.
Thank you!

Updated the PHP manual to reflect a more accurate memory usage estimate for range(0, 1000000).
Previous documentation stated it used over 100MB, but actual tests show around 18MB.
Revised the estimate to 10MB for better accuracy based on real-world testing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant