|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
oop
hi,
i recently finished my script which producesdecent results but is rather slow. so i tested a bit and discovered that the use of objects/classes was the reason for it. now i'm thinking about reducing the oop-elements. actually i don't really want to, because my code is now pretty easy to read und debug. how did u write ur scripts? many classes, no one at all? |
|
#2
|
|||
|
|||
|
RE: oop
~10 functions.
My program sux though with only 431 score max on the first wordlist. I'm thinking of redoing the way I choose words to place. |
|
#3
|
|||
|
|||
|
RE: oop
oops?... OOP!
I think the objects/classes are not the slow thing with PHP, but the fact that when you ask for an array of 1000 integers, you get an array of 1000 untyped variables with integer values. I suppose they have a lot of overhead and a copy operation (the heaviest in crossword solving) becomes 1000 memory allocations + 1000 object creations. I overcome the matter by using a single 400 char string for the entire crossword board. This is tricky; but keeps memory usage & management at low. Also I try to use reference assignment everywhere as possible; but this gives unexpected results many times. I still don't understand references well. Other form of speed-improvement is to analize conditionals and making the heavier operations on the least usual case when possible, as in: 1> $tmp=$this; 2> if ($tmp->find_better_solution()) 3> $this = $tmp; // Heavy CPU use for copying is faster than 1> $backup=$this; 2> if (!($this->find_better_solution())) 3> $this = $tmp; // Heavy CPU use for copying supposing that to find a better solution is less usual than not finding it. Also, I found that adding some 'unset($tmp)' with objects not needed improved the speed a lot. Ow, I am so boring. >-( |
|
#4
|
|||
|
|||
|
RE: oop
thanks for ur thoughts. i think too that memory allocation is a very time - consuming matter in general. but i don't believe this is what makes OOP in PHP slow. i rather think object creation is somewhat slow.
btw in the php manual it says references are not faster than copies since 4.0 . anyway i'd be happy if zend spent some time to improve the object oriented side of php. not only speed matters, but access restriction and error handling maybe like in java would be really neat. |
![]() |
| Viewing: Codewalkers Forums > PHP Contests > Older Contests > oop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|