07 Tem, 2007
str_replace Vs preg_replace aka Freddy Vs Jason :D
Posted by: Xcoder In: Geyik| Güncel| PHP| Programlama

Bugün Melih‘le uzun süreden sonra buluşup çay içme fırsatı bulduk.
İki programcı bir araya gelince muhabbet gene bilgisayara kaydı ve her nasıl olduysa muhabbet özel karakterleri temizlemede str_replace mi daha hızlı yoksa preg_replace mi daha hızlı tartışmasına dönüştü
Ben dedim preg_replace daha hızlıdır , Melih’de demez mi tek seferde array ile str_replace daha hızlı.
Bizde test etmeye karar verdik.
test için 1000 adet rassal olarak 100 karakterden oluşturulmuş string kullandık.
Test Platformu :
Processor #1 Vendor: GenuineIntel Processor #1 Name: Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz Processor #1 speed: 1399.953 MHz Processor #1 cache size: 2048 KB Processor #2 Vendor: GenuineIntel Processor #2 Name: Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz Processor #2 speed: 1399.953 MHz Processor #2 cache size: 2048 KB PHP 4.4.6 CENTOS Enterprise 4.5 i686 2 GB ram
Test sonuçları :
preg_replace süre 0.141883850098 saniye
str_replace süre 0.0498099327087 saniye
Sonuç :
Melih’e bi yemek borcu
Aslında ben birden fazla str_replace sanmıştım
test kodları