Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Optimization Tale Plus Question

Recommended Posts

Just figured I'd post this real quick as I found the experience fairly amusing.I was working on some code last week that, when I applied it to the full set of data, took about 1 hour and 10 minutes to run. Needless to say, this is quite slow, however I was using unoptimized code. I went for correctness first. Anyway, the first thing I noticed was that I could eliminate a good deal of array copying. I fixed that and it cut the time down to 23 minutes. This is still a lot slower than I wanted, so I went back to trying to optimize the code. After trying various things and researching some different things to optimize in Perl, I tried something completely and utterly stupid: I changed push to unshift. Now, I could do this since I was sorting the array later anyway, so ordering did not matter at this point.Did it work? The code ran in 34 seconds. I must say, I was quite shocked by this. This leads me to my question: what's the difference between push and unshift in terms of how they work? I know they put data on different sides of the array. I'm just wondering why that made such a profound performance difference.

Share this post


Link to post
Share on other sites

That is a bit shocking because internally perl manages arrays as lists. And push() and unshift() are almost the same when it comes to performance. Are you sure you are dealing with the same set of data and haven't changed anything else? Can you post a code snippet that I can look into?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.