nb Core Community
February 07, 2012, 09:45:36 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: 1.2.3 +nb is now final and released

@new registrations. I will not allow any new registrations here as there are more (real person) spambots here than ever.... captcha proved to be ineffective.

After your registration, mail me at ( admin AT shinobilegends.com ) from the mail address you want to register. Provide some text about you and possibly your game.
 
   Home   Help Search Calendar Downloads Login Register  
Pages: [1]
  Print  
Author Topic: Benchmarks  (Read 936 times)
coolgames
Guest
« on: December 02, 2007, 04:34:59 pm »

Well, this isn't really a BUG but i read:
Quote
**generic --> benchmarks resulted in a dramatic performance increase once the "while (list-each)" construct is replaced by i.e. "foreach" or "for". So I changed it in the entire core code (might have missed some). This should speed the game up a few milliseconds on a heavy trafficked server.
in the clangelog.

something seems to be in-correct
using (list-each) is known to be faster than foreach.

there are many companies that have tested it too   Cool
Logged
Nightborn
Administrator
Sr. Member
*****

Karma: +20/-0
Posts: 306



View Profile WWW
« Reply #1 on: December 08, 2007, 12:35:10 pm »

wrong.

=)

http://benchmark.nophia.de/benchmarks-arrays-k-4-for-foreach-while-fuer-kleine-arrays-b-7.html

30ms for a foreach, 150ms for a while(list()) ...

what are your sources?

if you like, run the following scripts in rawsql->php:

Code:
$array=array();
for ($i=0;$i<10000;$i++) {
  $array[]="Test-$i";
}
//filled, now test.
$start=microtime();
while (list($key,$val)=each($array)) {
//do something
}
$end=microtime();
output("While-Each lasted: %s ms",$end-$start);

$start=microtime();
foreach($array as $key=>$val) {
//do something
}
$end=microtime();
output("Foreach with key-val lasted: %s ms",$end-$start);


Note: foreach is even faster when you do not care about the key, but about the value only. Cheesy
Logged

It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro
coolgames
Guest
« Reply #2 on: January 14, 2008, 06:22:53 pm »

Note: foreach is even faster when you do not care about the key, but about the value only. Cheesy
yep, hehe i think i misunderstood the results in http://www.php.lt/benchmark/phpbench.php

you're right  Wink
sorry for wrong postification.  Undecided
Logged
Nightborn
Administrator
Sr. Member
*****

Karma: +20/-0
Posts: 306



View Profile WWW
« Reply #3 on: January 17, 2008, 04:17:33 pm »

+  415 %   1: foreach($aHash as $val);   Total time:    6[ms]
+  204 %   2: while(list(,$val) = each($aHash));   Total time:    3[ms]
+  853 %   3: foreach($aHash as $key=>$val);   Total time:   13[ms]
+  926 %   4: while(list($key,$val)= each($aHash));

if you have only one val, while -list *MIGHT* be faster, but it would be good to test that.

Here are my tests:

hirako:~/test# php test.php 100000
Test foreach took 0.045385ms.
Test foreach-ass took 0.065821ms.
Test for took 0.073692ms.
Test while took 0.069795ms.
Test while-list-each(ass) took 0.240931ms.
Test while-list-each(val) took 0.21557ms.

this is under PHP5, Zend, No accelerator, uncached.

The php source code was:

Code:
hirako:~/test# cat test.php
<?php
$tries
=(int)$argv[1];
if (
$tries==0$tries=100000;
$ass=array();
for (
$i=0;$i<$tries;$i++) {
        
$ass["Ad$i"]="Test$i";
}
$num=array();
for (
$i=0;$i<$tries;$i++) {
        
$num[]="Test$i";
}
$test= array(
        
"foreach"=>'reset($ass);foreach ($ass as $bla) {$b=0;}',
        
"foreach-ass"=>'reset($ass);foreach ($ass as $key=>$val) {$b=0;}',
        
"for"=>'for ($i=0;$i<$tries;$i++) {$num[$i]="x";}',
        
"while"=>'$i=0; while ($i<$tries) {$num[$i]="y";$i++;}',
        
"while-list-each(ass)"=>'reset($ass);while (list($key,$val)=each($ass)) {$b=0;}',
        
"while-list-each(val)"=>'reset($ass);while (list(,$val)=each($ass)) {$b=0;}',
        );


foreach (
$test as $name=>$code) {
        
$start=microtime();
        eval(
$code);
        
$end=microtime();
        echo 
"Test ".$name." took ".($end-$start)."ms.\n";
}
Logged

It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro
coolgames
Guest
« Reply #4 on: January 18, 2008, 02:04:53 pm »

if you have only one val, while -list *MIGHT* be faster, but it would be good to test that.
[color=Lime Green]Sadly, very few of the LoTGD core uses 1 Val..[/color]
i'll switch to foreach.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!