[Israel.pm] unshift vs push&reverse

Gabor Szabo szabgab at gmail.com
Thu Mar 26 02:29:14 PDT 2009

On Thu, Mar 26, 2009 at 11:13 AM, Berler Chanan <chananb at centerity.com> wrote:
> Hi All,
> I have a set of SQL needed to be run using timestamp field.
> I have created an array and needs to push / unshift the SQL statements into
> it for future execution
> (different conditions builds different set of SQL statements).
> I am using unshift to push  the values into an array, so I will have the
> correct order, but I wonder
> if it is best to use push and reverse functions instead.
> Can anyone direct me to performance of unshift vs. push&reverse ? or
> push&pop ?
> Thanks
> Chanan

Why do you care?
Please answer the following questions in order:

Does your code do what it has to do?
Is the code clear to your satisfaction?
Is there a performance issue ?
Have you profiled the code checking where is the performance issue?
Is the performance issue in the code that adds the SQL statements.

Then ask the above question.

BTW You are writing "I am using unshift to push  the values" which
would indicate
me that you are using the incorrect method. If you talk about pushing
values then
use that keyword it makes much more sense.

Besides the only place on Earth where a queue is implemented
with unshift is Israel. "Just asking a question".
(ok, not really)

ps. push should be way faster than unshift but I am quite sure it does not
matter in your code. If you want to check, benchmark them.

More information about the Perl mailing list