PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function calculateMemoryUsage($largeArray, $operation = 'sort') { $startMemory = memory_get_peak_usage(); switch ($operation) { case 'sort': sort($largeArray); break; default: throw new InvalidArgumentException("Unsupported operation: $operation"); } $endMemory = memory_get_peak_usage(); return $endMemory - $startMemory; } $largeArray = range(1, 100000); try { $memoryDiff = calculateMemoryUsage($largeArray, 'sort'); echo "Memory usage difference after sorting: $memoryDiff bytes\n"; } catch (InvalidArgumentException $e) { echo "Error: " . $e->getMessage() . "\n"; } ?>
Show:  
Copy Clear