/ Published in: PHP
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
for ( $i = 0; $i < 100000; ++$i ) { $myArray[] = $i; $myArray[] = 'test a string'; } for ( $i = 0; $i < 100000; ++$i ) { }