Author Topic: Thoughts on OOP and Process Memory Used  (Read 3109 times)

Offline Bryan

  • Level 7
  • *
  • Posts: 32
  • Reputation: +2/-0
    • View Profile
Thoughts on OOP and Process Memory Used
« on: January 15, 2010, 03:33:26 PM »
I don't know about my position on game coding with frameworks or OOP now.  ::)

I think I have changed my mind after considering the reality of the performance and memory consumption I saw.

After reading Codestryke's post (link) in the OOP discussion it dawned on me that I hadn't really ever put php's memory_get_usage() to good use in any of my projects to find out what was happening there.

Here is what I came up with on my local test server (windows vista, wamp, mySQL) with some comparisons on my CentOS server.  Both machines have close to the same specs hardware-wise (4 cpus, 8gb ram)  I didn't keep track of the microtime used, just wrote down the memory consumed.
All the bolded numbers are bytes
Magento clean install - 15,098,457 avg process memory used (scary - 15mb per 'page' view).
Magento store with ~150 products on CentOS server 12,338,200 (still pretty huge chunk of RAM for a home page)

SMF forums (like this forum) clean install 1,590,458 avg process memory used (pretty good, I suppose, compared to above).
SMF forums on my CentOS server 890,459 avg process memory used (this is why Linux is better for websites, I reckon)

I also have been toying with a game framework written with the Zend Framework - Full Application (uses all the ZF stuff)
Game Html Home Page (nothing too much going on, ZF application bootstrap, templates, some services and start a session) 5,230,690 avg process memory used. [ I didn't test this on the CentOS ]

Another experiment I have is using just the Zend_AMF with a Flash client -
Game Flash Home Page (nothing much again, starts a session, ZF AMF bootstrap) 3,466,888 avg process memory used. [ I didn't test this on the CentOS ]

Zend_Amf gateway without anything connected at all - 1,112,325 avg process memory used.
Zend Amf on the CentOS used a little less - 823,444 avg process memory used.

PureMVC basic application Facade, MVC and typical session, etc: 1,111,350 avg process memory used
[ I didn't test PureMVC on the CentOS ]
Here's a baseline for the machine:
php file that just echo's memory_get_usage() = 227,433 avg process memory used.

Same file on CentOS a mere 32,990 avg process memory used.
(WOW, what a difference between the two machines on that test!)
Test notes:
Averages made from only 100 processes in each test.

Leads me to wonder - how would a game perform in the long run using ZF and upwards of 6mb per process?
That's without anything happening, either - I mean, no game stuff - just the most basic session start and loading up classes to handle the MVC pattern, registry, etc.  But what an expensive process!

Anyone have some numbers on CodeIgnitor, Kohana, or other frameworks?  Anyone want to post a little comparison on how a game using some other code is acting?

addit - link to OOP discussion added

addit - Here I found a benchmark testing results for some common frameworks, procedural php, and straight html for a basic home page.  The numbers demonstrate a harsh reality for frameworks - they are, sadly, at least a factor of 10 slower than procedural php doing the same job.  Nothing on the memory used, but I can well imagine that it would have similar differences. :(  ( I know this test is a little older, but I doubt that any frameworks out there have significantly closed the gap between themselves and the procedural php results in the interim)
« Last Edit: January 15, 2010, 04:03:10 PM by Bryan »

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #1 on: January 16, 2010, 08:40:04 AM »
I assume that was with disabled optimizers? I guess they don't have as much impact on memory usage than on execution speed, but still...
Which PHP version did you use?

I can't say you made my day :)

The numbers are a number of times higher than I'd expect them to be...
it would be great if possible to compare codes with similar functionality, one procedural one OO
...I know OO would have higher result, but I'm interested in ratio

It made me run and test :) and so far I'm on 930kB which I don't like at all since it's still far from finished...
measured roughly described like
Code: [Select]
$var = memory_get_usage();
//some code
echo memory_get_usage()-$var;
I guess that's a right way?
I though that it's caused by dependency objects passed to another objects are not references but an independent objects, but it's not true,
they're really references... the execution time is cca 12ms which I was told is still very ok

I'm playing with it and it seems that the biggest memory hit is upon creation of a first object of a respective class... there's most likely some optimization (other than common referencing) since ref_count doesn't affect it, the objects in the script are not connected since their ref_count stays the same, even if I comment out creating some of them.
For example creation of my mysql class took cca 220kB (omg) but creating a second independent object took only 2kB.

Well...I believe there would be performance improvements in php's future versions, but still...

ehm...actually I'm on 5.3 which is kinda new :) so maybe 6 or following, hopefully...

Quote
this is why Linux is better for websites, I reckon
I'd image there would be many aspects considering OS that I wouldn't get into this in this thread (not that I'd know them :) I just guess)
« Last Edit: January 16, 2010, 08:49:12 AM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Marek

  • Level 18
  • *
  • Posts: 177
  • Reputation: +7/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #2 on: January 16, 2010, 10:15:24 AM »
Great report. Real performance data like this is very useful, and should be scrutinized more often.

I've worked with Drupal before. It's one of the best CMS's out there, but damn, does it use memory. I've seen page view reaching 30mb. Drupal's modular layout is the culprit for so much overhead. But on the other hand, the module system is pretty amazing in its functionality.

There's another useful function in PHP: memory_get_peak_usage(). You can run it at the end and it gives you the peak memory usage during the execution of the request.

Offline Bryan

  • Level 7
  • *
  • Posts: 32
  • Reputation: +2/-0
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #3 on: January 16, 2010, 01:26:42 PM »
I am using php 5.2.10.

echo, echo, Nox, rather than subtracting that first one.  I think that might be throwing your result off.  All the samples I found just use the output of that function or the peak one nano mentioned to show the memory allocated.
« Last Edit: January 16, 2010, 01:34:03 PM by Bryan »

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #4 on: January 18, 2010, 09:38:16 AM »
This is probably more because of how the PHP garbage collection process works. Personally, I tend not to put my trust in garbage collection with interpreted languages.

Supposedly, as of PHP 5.3, the garbage collection process has been made a bit better. Especially when calculating circular dependencies. I wish it was closer to C++ in that garbage collection was run based upon scope. I've actually thought about coding an extension to PHP to make it a little closer to C++ in a couple of regards:
Enumerated constants
Type-hinting functions for built-in types
Garbage collection at scope termination

Never really looked into it more than "I hate these things about PHP! Maybe I can change them sometime!" lol But, a man can dream, right? ;)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
PHP Memory usage...WTF?
« Reply #5 on: February 02, 2010, 03:16:32 AM »
Does anyone know how to measure function memory consumption?
Even conditioned creation of function (which afaik should postpone it's parsing) gives too small results

I continued playing with it and more results:
Code: [Select]
adding public properties
1st OO int = 840B
2nd OO int = 760B
3rd OO string = 800B
visibility no effect (public, protected..)
OO const int = 224B

P int = 288B
P const int = 144B


method (117 rows 3368 chars) = 67088B;
conditioned function (identical) = 144B
anonymous function (identical) = 904B

(PHP 5.3.1)

....the last two are obviously off, function having the same consumption as constant gives a hint



But the results are insane anyway... int taking 288B? Shouldn't it take 4B ....ok,maybe a bit more bytes... but that's 72x more!
Integer inside object takes for some reason 3x more memory, that's like 216x more than it should

No wonder the memory usage is like 100x higher that I'd expect

...do I have a mistake somewhere? Or interpret it badly? Is it badly configured or is PHP really that terrible about this?
Thank you
« Last Edit: February 02, 2010, 05:39:56 AM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: PHP Memory usage...WTF?
« Reply #6 on: February 02, 2010, 05:33:58 AM »
But the results are insane anyway... int taking 288b? Shouldn't it take 4b ....ok,maybe a bit more bytes... but that's 72x more!
Integer inside object takes for some reason 3x more memory, that's like 216x more than it should

No wonder the memory usage is like 100x higher that I'd expect

...do I have a mistake somewhere? Or interpret it badly? Is it badly configured or is PHP really that terrible about this?

That's one of the prices you pay for using a loosely-typed dynamic language.  That int isn't just the 4 bytes of numeric data, it's also a flag indicating what kind of data is stored there, how big "there" is, a reference count, etc.  Based on http://bugs.php.net/bug.php?id=41053 it looks like PHP 5.2.2RC1 was using about 68 bytes to store an int, but nobody said anything about where the extra 64 bytes went, aside from a vague mention of "memory allocation headers".

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #7 on: February 02, 2010, 05:57:11 AM »
I don't really agree with that...I know there's some metadata with it, but you need like 3 bits (so say 1 byte) to store type, reference count 2-4B maybe, etc. ... don't have a clue what those extra 284! bytes are for

A single property in object takes almost 1kB...



Ok, I didn't test property size totally correctly... a single extra property upon first object creation and parsing takes 840B... but in other instances take 72B/112B...that's still A LOT but better....weird that it's now actually less then a common variable in procedural code

Another weird thing is that adding 1 int to object increases it's instance memory cons. by 72, adding 2 by 184 which would suggest the latter using 112B...I don't get why one variable takes more than another. In case of the first object the size it's actually vice versa

Code: [Select]
public $x=6; //72B
public $y=5; //112B

I sense some dark magic here...
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #8 on: February 02, 2010, 06:06:41 AM »
Quote
I don't get why one variable takes more than another.
"not sure how this works internally but I have observed sort of side effects here: calling this function apparently triggers PHP's "garbage collector" -- and frees some memory. I managed to "fix" some savagely coded mess of a web application solely by calling this function just before the code that would usually throw out-of-memory errors. the php version there was 5.2.10"

Quote
Each element requires a value structure (zval) which takes 16 bytes.
Also requires a hash bucket - which takes 36 bytes. That gives 52 bytes
per value. Memory allocation headers take another 8 bytes*2 - which
gives 68 bytes.
Cute :D

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #9 on: February 02, 2010, 06:26:24 AM »
As stated before, this was in 5.3.1....so...I don't know... plus the memory_get_usage() was not called in between those two declarations so I still don't see a reason for different

Thank you, that explains a lot
although in case of int itself we still have 200B missing...
Code: [Select]
echo memory_get_usage()."<br>";
$x=5;
echo memory_get_usage();
die();
shows me 272 (288 previously was not correct)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #10 on: February 02, 2010, 06:39:09 AM »
I think '.' is using memory as well (since it joins strings).

Try:
Quote
memory_get_usage(); // force grabage collection (if any)
echo memory_get_usage();
echo '<br>';
$x=5;
echo memory_get_usage();
die();

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #11 on: February 02, 2010, 08:41:19 AM »
PHP is a scripted, dynamically-typed language. Thus, it will not take 4B to store an int. There is a certain amount of memory required just to parse the script. And, since it's dynamically-typed (which is something that I absolutely loathe) it stores more data than is actually necessary as was indicated above.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #12 on: February 02, 2010, 08:49:35 AM »
Even
Code: [Select]
memory_get_usage(); // force grabage collection (if any)
echo memory_get_usage();
$x=5;
echo memory_get_usage();
die();
returns 272...hmm... difficult the life of memory usage measurer is :)

JGadrow
I mentioned more than once that I'm fully aware of that.... but I was surprised that metadata is sometimes more then *two hundred* times larger than data itself...plus that it's variable
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #13 on: February 02, 2010, 09:08:38 AM »
It's not the metadata that's variable, it's the script. If you add a single statement, you've changed the amount of memory required to parse the script.

Additionally, I'm not positive, but I believe the first instance of a class will store more information than each subsequent instance as the metadata about the class, itself, was built with the first instance but was redundant beyond that one. So, to get an accurate measurement of the memory required per instance of a class you will need at least 3 instances. Again, I could be wrong here. I don't think this would be required for integral types, but I could be wrong about that as well.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #14 on: February 02, 2010, 09:29:34 AM »
correction again :/
$x=5; => $x; ... 128B

I do not measure the usage of whole script, I measure usage difference between two points....if the measuring function itself is implemented well then I'd think the code above should measure the memory usage of the code in between, right?

I'm confused about the number "3"... I'd suspect for the first instance there would be some extra work but I would be suprised if there's difference between 2nd and 3rd....

I actually mentioned it too

adding 1 property to class:
1st instance: 840B increase (not a little really)
2nd instance: 72B increase

adding 1 more property to class
1st instance: 760B increase
2nd instance: 112B increase

1 more:
1st: +800B
2nd: didn't measure

BTW - do you happen to know how to measure memory usage of function definition?

Because I measured object's 1st instance memory usage and then commented out the largest method -> resulted in 70kB! less usage (from 210kB... out of which I guess like 205kB are methods)

I'd like to compare it with common procedural function, I'd expect there would be difference even though it's not really logical (to me)....
I will be afraid to even use assignment and basic operations now...
sorry, bitterness kicking in
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #15 on: February 02, 2010, 09:49:29 AM »
If you use 3, you can see if the usage is the same for each subsequent instance.

First instance (initialize class data)
Second instance memory use - First instance memory use = REAL memory increase
Third instance memory use - Second instance memory use = sanity check on memory increase

Also, according to php.net's example of memory_get_usage, you can see that the more of a script that executes, the more memory is required. Look at the example, you would expect that releasing the variable would re-set the memory to the original usage, but that is not the case.

Also, it looks like if you don't pass a parameter of true to the memory_get_usage function, you're actually not getting the whole story. ;)
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #16 on: February 02, 2010, 10:11:44 AM »
Got better benchmark (but still not working correctly :D).
Quote
memory_get_usage(); // just in case of forced garbage collector

$a=1; $b=1; // reserve memory for memory_get_usage results
$a=memory_get_usage();
$x=5; // use memory: 1x INT
//$y=5; // another variable
//$z=5; // and another
$b=memory_get_usage();

$d=$b-$a;
echo "Before: $a<br>";
echo "After: $b<br>";
echo "Difference:$d<br>";
die();
= 24 bytes per INT (which is plain wrong since it should be 32 bytes minimum...)
When added second variable the result was 96...

Do not forget that almost everything use memory. Seems the memory_get_usage function does not return variable buffer size but the total memory used by php script.

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #17 on: February 02, 2010, 10:17:49 AM »
Okey, I give it up :) I guess it can't be reduced anyway....
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #18 on: February 02, 2010, 10:29:50 AM »
Yeah, there's a high price for convenience. lol Personally, I actually like static-typed languages simply because they force the programmer to actually declare their intent for the code and force the client (any calling / accessing code) to respect that intention.

I'm sure there's a language (other than C++) that I'd like better than PHP if I had the time to try it out and learn it. But, PHP works for the time-being and there's a job market for it.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #19 on: February 02, 2010, 10:34:19 AM »
Guys, I made a great discovery! If you use memory_get_usage(true) all your variables will use 0 memory! Nobel prize for me for discovering this awesome RAM usage reduction method :D
(might require certain PHP/apache combo)

OK, I give up too, will use intuition for benchmarking.

Offline Delifisek

  • Level 12
  • *
  • Posts: 79
  • Reputation: +1/-1
    • View Profile
Re: Thoughts on OOP and Process Memory Used
« Reply #20 on: February 03, 2010, 06:30:45 PM »
After some flamewars in our local boards. we generate following (a bit non sense) benchmark.

It generates php files which contains 10.000 functions, or classes and executes them.

Code: [Select]
<?php
$dosya 
"<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"
$dosya.= "\n\n";
$fcall "\n\n\n#Calling Functions\n";
for(
$i=0;$i<10000;$i++) {
$dosya.= "function load".$i."(\$degisken) { return \$degisken; }\n";
$fcall.= "\necho load".$i."('execution_function_load".$i."');\n";
$fcall.= 'echo "\n";';
}
$dosya.=$fcall."\n\n";
$dosya.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";
$tut=fopen('testfonk.php','w+');
fputs($tut,$dosya);

$dosya = "<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"; 
$dosya.= "\n\n";
$ocall = "\n\n\n#Calling Objects\n";
$close '';
for(
$i=0;$i<10000;$i++) {
if($i%10==0) {
$dosya.= $close."class load".($i/10)."{\n"
$close "\n}\n\n"
$objn  = ($i/10);
$ocall.= "\n\$myobj".($objn)." = new load".($i/10)."('');\n\n";
}
$dosya.= "\tfunction load".$i."(\$degisken) { return \$degisken; }\n";
$ocall.= "\necho \$myobj".($objn)."->load".$i."('execution_function_load".$i."');\n\n";
$ocall.= 'echo "\n";';
}
$dosya.= "}\n";
$dosya.= $ocall ."\n\n";
$dosya.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";

$tut=fopen('testoop.php','w+');
fputs($tut,$dosya);

//--- 10000 obje
$dosya = "<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"; 
$dosya.= "\n\n";
$ocall = "\n\n\n#Calling Objects\n";
$close '';
for(
$i=0;$i<10000;$i++) {
$objn  $i;

$dosya.= $close."class load".$objn."{\n"
$close "\n}\n\n"
$ocall.= "\n\$myobj".($objn)." = new load".($objn)."('');\n\n";

$dosya.= "\tfunction load".$i."(\$degisken) { return \$degisken; }\n";
$ocall.= "\necho \$myobj".($objn)."->load".$i."('execution_function_load".$i."');\n\n";
$ocall.= 'echo "\n";';
}
$dosya.= "}\n";
$dosya.= $ocall ."\n\n";
$dosya.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";

$tut=fopen('testoop2.php','w+');
fputs($tut,$dosya);

//--- 10000 obje unset
$dosya = "<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"; 
$dosya.= "\n\n";
$ocall = "\n\n\n#Calling Objects\n";
$close '';
for(
$i=0;$i<10000;$i++) {
$objn  $i;

$dosya.= $close."class load".$objn."{\n"
$close "\n}\n\n"
$ocall.= "\n\$myobj".($objn)." = new load".($objn)."('');\n\n";

$dosya.= "\tfunction load".$i."(\$degisken) { return \$degisken; }\n";
$ocall.= "\necho \$myobj".($objn)."->load".$i."('execution_function_load".$i."');\n\n";
$ocall.= "\n unset(\$myobj".($objn).");\n\n";
$ocall.= 'echo "\n";';
}
$dosya.= "}\n";
$dosya.= $ocall ."\n\n";
$dosya.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";

$tut=fopen('testoop3.php','w+');
fputs($tut,$dosya);

//--- Object clone
$dosya = "<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"; 
$dosya.= "\n\n";
$dosya.= "class load {
function myload(\$degisken) {  return \$degisken; }
}\
n";
$dosya.= "\n\n";
$dosya.= "\$myobj = new load('');\n";

$ocall = "\n\n\n#Calling Objects\n";
$close '';
for(
$i=0;$i<10000;$i++) {
$objn  $i;

$ocall.= "\n\$myobj".($objn)." = clone \$myobj;\n\n";
$ocall.= "\necho \$myobj".($objn)."->myload('execution_function_load".$i."');\n\n";
$ocall.= "\n unset(\$myobj".($objn).");\n\n";
$ocall.= 'echo "\n";';
}

$dosya.= $ocall ."\n\n";
$dosya.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";

$tut=fopen('testoop4.php','w+');
fputs($tut,$dosya);


//--- Multi Static
$dosya = "<?php\n";
$dosya.= "\$start = (float) array_sum(explode(' ',microtime()));\n"; 
$dosya.= "\n\n";
$ocall = "\n\n\n#Calling Objects\n";
$close '';
for(
$i=0;$i<10000;$i++) {
$objn  $i;

$dosya.= $close."class load".$objn."{\n"
$close "\n}\n\n"
$ocall.= "\n\$myobj".($objn)." = new load".($objn)."('');\n\n";

$dosya.= "\tpublic static function my_load".$i."(\$degisken) { return \$degisken; }\n";
$ocall.= "\necho load".$objn."::my_load".$i."('execution_function_load".$i."');\n\n";
$ocall.= 'echo "\n";';
}
$dosya.= "}\n";
$dosya.= $ocall ."\n\n";


I suggestcheck with mod_phpPHP CLI performance far different than mod_php especially under siege
$dosya
.= "\$end = (float) array_sum(explode(' ',microtime()));\n";
$dosya.= 'echo "Memory Consumption : ".number_format(memory_get_peak_usage())." Mb.";';
$dosya.= "\n\n";
$dosya.= 'echo "Execution Time : ". sprintf("%.4f", ($end-$start))." Seconds.";';
$dosya.= "\n?>
";

$tut=fopen('testoop5.php','w+');
fputs($tut,$dosya);
?>

I suggest, use with mod_php. mod_php with apache performace far different than PHP CLI, especially under siege...

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal