0

Is branch prediction a big issue in PHP too?

I am referring to this answer: Why is processing a sorted array faster than an unsorted array?

So in C++ and Java a sorted array is computed faster than an unsorted, because the processor can predict the next steps correctly.

Would this refer to PHP programs the same way?

Community
  • 1
  • 1
rubo77
  • 19,527
  • 31
  • 134
  • 226
  • 2
    Unlikely: in PHP, an array is a hashmap, no prediction involved – Mark Baker May 30 '14 at 07:24
  • So there is no way of getting a benefit by this? Maybe you could use different arrays, than the standard php arrays (which are hashmaps indeed) to achieve an advantage? – rubo77 May 30 '14 at 07:27
  • Double linked hashmap. – sectus May 30 '14 at 07:31
  • 1
    @MarkBaker, the reason why the sorted array behaved better had nothing to do with its memory layout. Accessing a sorted hash map may also work better in terms of branch prediction, if it means that your CPU keeps going through the same control flow path. – Leeor May 30 '14 at 21:26
  • this question has an anwer here http://stackoverflow.com/questions/11294457/branch-prediction-at-php – jameshwart lopez Dec 18 '15 at 06:37
  • Does this answer your question? [Branch prediction at php](https://stackoverflow.com/questions/11294457/branch-prediction-at-php) – Mike Doe Dec 30 '19 at 08:40

0 Answers0