Skip to content

Instantly share code, notes, and snippets.

@saroarhossain57
Created March 25, 2024 07:04
Show Gist options
  • Save saroarhossain57/835b45df204dba5cd5bc7c1e9428098f to your computer and use it in GitHub Desktop.
Save saroarhossain57/835b45df204dba5cd5bc7c1e9428098f to your computer and use it in GitHub Desktop.
Get and Analysis Memory and Execution time in PHP.
<?php
$start_mem = memory_get_usage();
$start = hrtime(true);
$array = range(1, 100000);
$end = hrtime(true);
$end_mem = memory_get_usage();
$mem_usage = $end_mem - $start_mem;
// Calculate the execution time
$execution_time = ( $end - $start ) / 1000000;
echo $mem_usage . " Bytes or " . $mem_usage / 1000000 . " MB \n";
echo "Execution Time: " . $execution_time . " MS";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment