Speed Test: array_push vs $array[]


/ Published in: PHP
Save to your folder(s)

Took 0.164692 seconds for array[]
Took 0.395778 seconds for array_push

As you can see array_push is more than twice as slow. Here are the reasons. Array_push is a function call, Function calls are always slower. Array_push takes mixed parameters, parameter checking is always slower. Also array[] just looks cleaner and is less to type.

Tips: Always pre-intialize your variables and don't use mixed types even though you can.

URL: http://www.mthorn.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.