Gerçekten yerine PHP of "kullanmak 'bir etkiye sahip

5 Cevap php

Bir web sitesi, kod 5 insan yıl (5 geliştiriciler, yaklaşık bir yıl), binlerce hit 10 her gün. Gerçekten biz mümkün 'tüm "değiştirirseniz bir etkisi olacak mı?

5 Cevap

PHPBench (sayfa sonuna gidin) de double (") vs. single (') quotes bölümüne bakın. Ben sayfa çağrıldığında, ben şu sonuçları gördüm:

Single Quotes: 257 µs
Double Quotes: 232 µs

25μs Sorununuz etki için bir fark yapar sürece, o önemli değil.

Ben bir hata yaparsam ben burada matematik çalışmak için denemek için gidiyorum, birisi beni düzeltin. Diyelim ki olurdu sayfa yükleme (kim aslında bu şekilde çalışacaktır eğer, kriter gerçek kodu gerekir bilir) başına 25μs farkı çift tırnak yerine tek tırnak kullanılan 10.000 yerleri bir bir olacağını var diyelim yürütme zamanında 0.25 saniye fark. Facebook olsaydı o sunucu yüküne bağlı olarak önemli olabilir. Ancak, sen bile tırnak bakmak önce optimize etmek isteyeceksiniz yoğun çok fazla kaynak vardır sizin kod temeli çok başka yerlerde olduğunu sanıyorum. Sadece PhpBench sayfada highlighed ağrı noktalarına bakmak ve size farklı öncelikleri olması gerektiğini göreceksiniz. Bazı performans darboğazları çözebilir - sizin gibi Quercus, farklı bir php uygulama çalıştırırsanız Ayrıca, bu rakamlar büyük ölçüde farklı olacaktır.

Hayır.

Biri (ben sorunu "karşı 'aynı olduğunu düşünüyorum) bir kaç hafta geri PHP mikro-optimizasyon söz işaret ettiği gibi, optimizasyonu uygulanması hemen hemen her zaman hiç onun tarafından kaydedilmiş olacağını daha fazla zaman mal olacak.

Evet, bir hata size "$test\n" '$test\n' değiştirebilirsiniz nerede olduğunu yapma bitireceğiz.

Gerçek sayılar-bilge, hayır.

Bir mikro-Optimiztion denemede zaman harcama riski kod yönleri (ve herhangi bir üçüncü parti bağımlılıkları) / çok daha iyi bir verimlilik ile optimize / refactored sonra, profilli olmalıdır ki (henüz tespit edilmesi) muhtemelen olmasıdır adam-saat-harcanan oranı başına artış.

Ben okumak Remember also the rules of Optimization Club Bu yeterli tavsiye edemez.

There is no difference in peformance at run time. But there is a difference at compile time.
The usual way of thinking about quotes in PHP is:

Variables inside single-quoted strings are not parsed, and so the PHP engine doesn't have to waste time looking for them. Hence, single-quoted strings must be more efficient

That assumption is false because the PHP engine doesn't perform that ckeck at run time, but at compile time.
When PHP is parsing your script, if it finds a double-quoted string that has no variables inside it, then that string is treated as a constant string, i.e. its value won't change in the entire script's life-time (if there are variables inside, then it's converted to string concatenations).
Likewise, if PHP finds a single-quoted string, it is treated as a constant as well. But in this case PHP doesn't have to parse the content of the string lookng for variables.

So the answer to your questions depends on whether you are using a PHP caching solution or not (APC, eAcceleator, etc...). If the compilations of your scripts are not being cached then you might have a slight performance improvement because your scripts are compiled every time a visitor loads a page, and hence compilation time is important. But if the compilations of your scripts are cached, then there is no different on using single- vs double-quoted strings.