Re: > 120 meg of json analyzed by the browser...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 28, 2010 at 4:04 PM, Robert Cummings <robert@xxxxxxxxxxxxx> wrote:
> Use get_memory() to see just how much memory you're using. Somewhere in your
> script you are probably storing much more memory than you think.

My functions do print the memory usage;
I'm just wondering why the array returned is 1/5th of the desired (and
allocated) size.


global $hmGenKeys;
$hmGenKeys = 0;
global $hmGenKeysDone;
$hmGenKeysDone = 0;
function htmlMicroscope_generateRandomArray ($maxKeys, $maxDepth,
$maxDuration=-1, $maxMem=-1) {
  global $hmGenKeys;
  global $hmGenKeysDone;

  $r = array();
  $l1 = false;
  if ($maxKeys!==null) {
    $hmGenKeys = $maxKeys;
    $l1 = true;
  }

  $hmGenKeys--;
  if ($hmGenKeys<=0) return false;
  if ($maxDepth<=0) return false;
  if ($l1) {
    srand(htmlMicroscope_randMakeSeed());
    while ($hmGenKeys > 0) {
	$hmGenKeys--;
	$hmGenKeysDone++;
	file_put_contents('countdown.txt',
	    'k:'.number_format($hmGenKeysDone,0,'.',',').
	    ' m:'.number_format(memory_get_usage(true),0,'.',',')
	);
	if ($maxMem!=-1 && memory_get_usage(true) > $maxMem) return $r;
	if ($maxDuration!=-1 && $maxDuration < getDuration()) return $r;

	switch (rand(1,2)) {
	  case 1 :
	    $next = htmlMicroscope_generateRandomArray (null, $maxDepth-1,
$maxDuration, $maxMem);
	    if ($next!==false)
	      $r +=  array(
		htmlMicroscope_randomValue(4) => $next
	      );
	    break;
	  case 2 :
	    $r += array(
	      htmlMicroscope_randomValue(4) => htmlMicroscope_randomValue(20)
	    );
	    break;
	}
    }
  } else {
    $range = rand(0,50);
    for ($i=0; $i<$range; $i++) {
	$hmGenKeys--;
	$hmGenKeysDone++;
	file_put_contents('countdown.txt',
	    'k:'.number_format($hmGenKeysDone,0,'.',',').
	    ' m:'.number_format(memory_get_usage(true),0,'.',',')
	);
	if ($maxMem!=-1 && memory_get_usage(true) > $maxMem) return $r;
	if ($maxDuration!=-1 && $maxDuration < getDuration()) return $r;

	switch (rand(1,2)) {
	  case 1 :
	    $next = htmlMicroscope_generateRandomArray (null, $maxDepth-1,
$maxDuration, $maxMem);
	    if ($next!==false)
	      $r +=  array(
		htmlMicroscope_randomValue(4) => $next
	      );
	    break;
	  case 2 :
	    $r += array(
	      htmlMicroscope_randomValue(4) => htmlMicroscope_randomValue(20)
	    );
	    break;
	}
    }
  }

  if (($hmGenKeysDone/7919)==round($hmGenKeysDone/7919)) sleep(1);

  return $r;
}

function htmlMicroscope_randomValue($maxLength) {
  $r = '';
  switch (rand(0,9)) {
    case 0 : $r = rand (0,100000000); break;
    case 1 : $r = rand (0,100000000) / rand(1,100) / 3; break;
    default:
	switch (rand(0,1)) {
	  case 0:
	  $rnd = rand(1,$maxDepth);
	    for ($i = 0; $i < $rnd; $i++) {
	      $r.= unichr(rand(0,hexdec('ffff')));
	    }
	    break;
	  case 1:
	    for ($i = 0; $i < $maxLength; $i++) {
	      $r.=chr(rand(ord('a'),ord('z')));;
	    }
	    break;
	}
	break;
  }
  //echo $r.'<br/>'.$maxLength.'<br/>';
  return $r;
}

function htmlMicroscope_randMakeSeed() {
  list($usec, $sec) = explode(' ', microtime());
  return (float) $sec + ((float) $usec * 100000);
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux