Phorum.ro
Your Avatar Welcome to Phorum.ro!
If you haven't registered yet, click here!
Attention Visitor:
You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Du-te înapoi   Phorum.ro > Web Design & Web Development > Programare > PHP > Discutii Generale

Discutii Generale Discutii generale despre PHP.

Răspunde
 
Thread Tools Moduri de afișare
Vechi 12.05.2006   #21
outkast
64-Bit member
 
outkast's Avatar
 
Data înregistrării: 06.02.2006
Locație: Romania
Vârsta: 27
Mesaje: 227
Rep Power: 7
outkast is on a distinguished road
Implicit

poti sa-l faci in orice limbaj c/c++ , pascal, basic .... atata timp cat nu este un limbaj interpretat.
algoritmul ala se numeste "Sieve of Eratosthenes" si din cate stiu eu e cel mai rapid. poate fi optimizat in sensul ca poti sa impachetezi flagurile din vectorul a[] si in loc sa tii cate un flag pe element poti memora cate 32 de flaguri in fiecare element (cate 1 bit pt fiecare) si reduci consumul de memorie destul de mult.
inca ceva, incearca sa te feresti de functii matematice cum ar fi sqrt(), pow() etc fiindca sunt destul de lente.
__________________
A good Manager will take you through the forest, no mater what. A Leader will take time to climb on a tree and say 'This is the wrong forest'

blog.florindinu.ro - Another boring blog
outkast is offline   Reply With Quote
Sponsored Links
Vechi 13.05.2006   #22
szz
32-Bit Member
 
szz's Avatar
 
Data înregistrării: 10.09.2005
Mesaje: 41
Rep Power: 7
szz is on a distinguished road
Implicit

In general, algoritmul postat de outkast e f ok, mai poate fi optimizat putin in ceea ce priveste memoria (si rapiditatea):

Cod:
 $n)
     break;
  if ($n%$prim == 0)
  {
   $isPrim = FALSE;
   break;
  }
 }
 if ($isPrim)
    $prime_numbers[] = $n;
}

print "Lista generata in " . (microtime(TRUE) - $start_time) . " secunde:";

// afisare numere prime
foreach($prime_numbers as $prim)
{
 print "$prim ";
}

?>
ps: pana la 150000 in <3 sec la mine pe calc.
__________________
http://www.petz.ro

"Linux is only free if your time has no value."
"Simplicity takes effort - genius, even."

...
szz is offline   Reply With Quote
Vechi 14.05.2006   #23
indy2kro
32-Bit Member
 
indy2kro's Avatar
 
Data înregistrării: 26.02.2006
Locație: Bucuresti
Vârsta: 27
Mesaje: 173
Rep Power: 7
indy2kro is on a distinguished road
Trimite un mesaj prin Yahoo pentru indy2kro
Implicit

Scripturile php rulate pe localhost depind enorm de mult de configuratia calculatorului, dimensiunea/incarcarea memoriei, configuratia php, folosirea unui program de optimizare etc.

E destul de greu sa afirmi ca un astfel de script va rula sub n secunde pe orice calculator (timpii pot varia destul de mult chiar si pe acelasi calculator) ... in principiu un script care doar calculeaza numerele respective (fara afisare la consola - eventual intr-un fisier) ar rula sub o secunda in C/C++ cam pe orice calculator, sunt doar niste operatii matematice relativ elementare. PHP-ul, numai prin faptul ca este un interpretor pur si simlpu nu a fost optimizat pentru rezolvarea unor probleme matematice intr-un timp cat mai scurt.
indy2kro is offline   Reply With Quote
Răspunde


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Moduri de afișare

Reguli de postare
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Pornit
emoticoanele sunt Pornit
Codul [IMG] este Pornit
Codul HTML este Pornit



Ora este GMT +3. Ora este acum 01:57:01.


Rulează cu: vBulletin Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Forum SEO by Zoints

XXXXXXXXXXXXXXXXXXX
Inactive Reminders By Icora Web Design