|
|
|
|
![]() ![]() |
Jan 11 2006, 09:34 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
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. |
|
|
|
Feb 5 2006, 08:51 AM
Post
#2
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 40 Joined: 29-January 06 Member No.: 17,841 |
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?
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 27th July 2008 - 01:46 AM |