LinkedList and ArrayList  Iterator speeds

Is an ArrayList Iterator hugely faster than a LinkedList Iterator?
I have swapped, for storing my 8000 dataObjects, from using an ArrayList to a LinkedList and all seems fine except that the Iterator I get is much slower (by more than 10 times slower)
I have scoured my code but I have come to the conclusion that a LinkedList is just slow
Id just like one of you to comfirm my beliefs

How odd.
According to Bruce Eckel's Thinking in Java [p.505]
(downloadable for free at
http://www.mindview.net/Books/TIJ/ ), LinkedList
should be faster than ArrayList for iteration,
insertion, and removal; and only slower for getting by
index.
I haven't done any tests of my own on it, but it makes
sense. I don't know why your LinkedList iterators
would be slower.Yes, LinkedList will be faster at inserts/deletes and slower at indexed lookups. Keep in mind that when you say myLinkedList.get(7000) the iterator has to go through 6999 objects to retrieve the 7000th object. When you do the same thing on an ArrayList it just goes directly to that index and returns it.

Similar Messages

  • Iterating performance: ArrayList, LinkedList, and Hashmap for N 1,000,000

    I have seen some websites discussing about the performance of ArrayLists, LinkedLists, and Hashmaps:
    http://forum.java.sun.com/thread.jspa?threadID=442985
    http://java.sun.com/developer/JDCTechTips/2002/tt0910.html
    http://www.javaspecialists.co.za/archive/Issue111.html
    http://joust.kano.net/weblog/archives/000066.html
    If I understand it right an ArrayList in general is faster for accessing a particular element in the collection and I can't find some pro's of using a LinkedList.
    My question is: If I only use a large collection with more than 1 million elements for iterating from begin to end (i.e. for loop), is it faster to use a linked list or a custom linked list instead of an arraylist (or hashmap)? Since you can iterate "directly" through a (custom) linked list, which is not possible with a arraylist?
    Edited by: 9squared on Nov 23, 2007 1:48 PM

    Thanks for the help, I wrote some code and tested it
    import java.util.ArrayList;
    import java.util.List;
    import java.util.LinkedList;
    public class TestTemp {
         public static void main(String[] args) {
              List<Node> a = new ArrayList<Node>();
              Node b = new Node("a");
              String[] c = new String[10000000];
              Node temp = b;
              for (int i = 0; i < 10000000; i++)
                   a.add(new Node("a"));
                   temp.next = new Node("b");
                   temp = temp.next;     
                   c[i] = "c";
              long tstart;
              tstart = System.currentTimeMillis();
              for (int i = 0; i < 10000000; i++)
                   c[i] = "cc";
                   if (i%200000 == 0)
                        System.out.println("Array " + i + ": " + (System.currentTimeMillis()-tstart));
              tstart = System.currentTimeMillis();
              temp = b;
              for (int i = 0; i < 10000000; i++)
                   temp.next.text = "bb";
                   temp = temp.next;
                   if (i%200000 == 0)
                        System.out.println("LinkedList " + i + ": " + (System.currentTimeMillis()-tstart));
              tstart = System.currentTimeMillis();
              for (int i = 0; i < 10000000; i++)
                   a.get(i).text = "aa";
                   if (i%200000 == 0)
                        System.out.println("ArrayList " + i + ": " + (System.currentTimeMillis()-tstart));
    public class Node {
         public String text;
         public Node next;
         public Node(String text)
              this.text = text;
    }Here are some results in milliseconds, and indeed just iterating doesn't take very long
    Elements     Linked     Arraylist     Array
    200000     0     0     1
    400000     5     13     5
    600000     9     22     9
    800000     14     32     12
    1000000     20     42     16
    1200000     25     52     19
    1400000     31     63     23
    1600000     37     72     26
    1800000     42     82     30
    2000000     47     92     33
    2200000     51     101     37
    2400000     56     112     40
    2600000     60     123     44
    2800000     65     134     47
    3000000     69     143     51
    3200000     73     152     55
    3400000     78     162     59
    3600000     84     175     63
    3800000     103     185     67
    4000000     108     195     70
    4200000     113     207     74
    4400000     117     216     78
    4600000     122     225     81
    4800000     127     237     85
    5000000     131     247     88
    5200000     136     256     92
    5400000     142     266     97
    5600000     147     275     101
    5800000     153     286     107
    6000000     159     298     113
    6200000     162     307     117
    6400000     167     317     121
    6600000     171     326     125
    6800000     175     335     128
    7000000     180     346     132
    7200000     184     358     136
    7400000     188     368     139
    7600000     193     377     143
    7800000     197     388     147
    8000000     201     397     150
    8200000     207     410     154
    8400000     212     423     157
    8600000     217     432     162
    8800000     222     442     167
    9000000     227     452     171
    9200000     231     462     175
    9400000     236     473     178
    9600000     242     483     182
    9800000     249     495     185
    10000000     257     505     189

  • LinkedList class and ArrayList class

    Hi everyone,
    What is difference between LinkedList class and ArrayList class ??

    Hi samue!
    If you had typed that question you would have got many answers.anyway
    difference between Linked List and ArrayList
    1.In linked list each element is stored as an object but not in arraylist
    2.Linked list need iterator to go through its contents but not arraylist
    3.reading element from each takes same time but if you want to add or remove element from the arraylist it takes considerable amount of time depending on the index number. in Linkedlist case it takes constant amount of time to add/remove at any index.
    this should be enough guess to know the difference but if u need try goooogle

  • Iteration Speed issue when Indexing 3D array wried to a while-loop

    Brief Description of my Program:
    I am working on the real-time signal generation by using LabView and DAQmx (PCI-6110 card). My vi reads the big data file (typically 8MB txt file containing about 400,000 samples (complex double precision). Then, the signal is pre-processed and I end up with a huge 3D array to feed while-loop (typically 3D array dimension is N x 7 x M where N & M >> 7). Inside the loop, that 3D array is indexed and processed before the results are written to the DAQmx outputs. I have a speed issue when indexing the large 3D array (i.e, 3D array having a large sub-array size). My while-loop could not run fast enough to top-up the DAQmx AO buffer (at the output rate of 96kHz). It could run faster only if I use smaller 3D array (i.e, smaller-sized sub-arrays). I do not quite understand why the size of 3D sub-array affects the rate of looping although I am indexing same sub-array size at each iteration. I really appreciate your comments, advices and helps.
    I include my 3D array format as a picture below.
    Question on LabView:
    How does indexing an 3D array which wires to the while-loop affect the speed of the loop iteration? I found that large dimension of sub-arrays in the 3D array slows down the iteration speed by comparing to indexing the same size of sub-array from smaller-sized sub-arrays of the 3D array to perform signal processing inside the while-loop. Why? Is there any other way of designing LabView Program to improve speed of iteration?
    attachment:

    Thank you all for your prompt replies and your interests. I am sorry about my attachment. But, I have now attached a jpg format image file as you suggested.
    I had read the few papers on large data handling such as "LabVIEW Performance and Memory Management". Thus, I had already tried to avoid making unnecessary copies of data and growing arrays in my while-loop. I am not an expert on LabView, so I am not sure if the issues I have are just LabView fundamental limitations or there are any other ways to improve the iteration speed without reducing the input file size and DAQ output rate.
    As you request, I also attach my top-level vi showing essential sections such as while-loop and its indexing. The attached file is as an image jpg format because the actual vi including Sub-VIs are as big as 3MB in total. I hope my attachment would be useful for anyone who would like to reply my question. If anyone would like to see my whole vi & llb files, I would be interesting to send it to you by an e-mail privately and thus please provide your e-mail address.
    The dimension of my 3D array is N x 7 x M (Page x Row x Column), where N represents number of pages in 3D array, and M represents the size of 1D array.  The file I am currently using forms 3D array of N = 28, & M = 10,731.  Refering to the top-level vi picture I attached, my while-loop indexes each page per iteration and wrap-around.  The sub-VI called "channel" inside the while-loop will further index its input (2D array) into seven of 1D arrays for other signal processsing.  The output from that "channel" sub-VI is the superposition of those seven arrays.  I hope my explaination is clear. 
    Attachement: 3Darray.jpg and MyVi.jpg
    Kind Regards,
    Shein
    Attachments:
    3Darray.jpg ‏30 KB
    MyVI.jpg ‏87 KB

  • Put Linkedlist into arraylist ???

    hello,
    i have a linkedlist of objects of size 1000. Every object(every node of linked list is an instance of a class) in linkedlist contains of 20 variables. Now i want to take objects from this linkedlist and put it into array list.???
    Example: If User says me i want to see linked list between range 30 to 200. So i want to take get object 30 to object 200 from linkedlist. I have decided to put into an array and pass it to my other class which would perform some calculation on these objects. I am unable to get objects from linkedlist and put into array list.

    import java.util.*;
    public class ListConvert {
        public static void main(String[] args) {
         LinkedList<String> ll = new LinkedList<String>();
         ll.add("test");
         ArrayList<String> al = new ArrayList<String>(ll);
         System.out.println(al.get(0));
    }

  • Since updating to ios 4.3.4 songs and podcasts have speeded up. Music goes faster, people talk faster in podcasts.

    Since updating to ios 4.3.4 songs and podcasts have speeded up. Music goes faster, people talk faster in podcasts.

    In the podcast playing screen there is a box on the left just under the scrubber bar.  It has a 1/2X. 1X or 2X. Those are the playback speeds.  Tap on the box to cycle through and change the playback speed.

  • 20 technical tips and tricks to speed SAP NetWeaver Business Intelligence

    20 technical tips and tricks to speed SAP NetWeaver Business Intelligence query, report, and dashboard performance (note: for technical people).
    http://csc-studentweb.lr.edu/swp/Berg/articles/NW2009/NW2009_20_technical_tips_tricks_speed_SAP_BI_performance.ppt
    Dr. Berg

    thanks....

  • Copy and Paste Variable Speed Ramp Curves?

    Is there any way to copy and paste variable speed ramp curves from one shot to another.
    I've got a rough cut with lots of speed ramps, and now I have to conform renders that came back from Color (pre-prepped with out ramps) to the offline with the same frame ramps.
    I can't seem to do it any other way than by eye match, which is less than great.

    Right click a clip in the Timeline that has the settings you want to transfer. Choose Copy.
    Right click a clip in the Timeline that you want to transfer the settings to. Choose *Paste Attributes > Speed.*

  • I have problem with data transfer between Windows Server 2012RT and Windows7 (no more than 14kbps) while between Windows Sever 2012RT and Windows8.1 speed is ok.

    I have problem with data transfer between Windows Server 2012RT and Windows7 (no more than 14kbps) while between Windows Sever 2012RT and Windows8.1 speed is ok.

    Hi,
    Regarding the issue here, please take a look at the below links to see if they could help:
    Slow data transfer speed in Windows 7 or in Windows Server 2008 R2
    And a blog here:
    Windows Server 2012 slow network/SMB/CIFS problem
    Hope this may help
    Best regards
    Michael
    If you have any feedback on our support, please click
    here.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • 2006 Mac Pro (OSX 10.7.5) and USB 3 speeds

    I'm considering the purchase of a HighPoint RocketU 1144CM USB 3.0 PCIe card and would like to know if there's anything in the architecture of my 2006 Mac Pro [Build 1,1] which might limit throughput speeds to USB2 standards. The manufacturer's [HighPoint] website claims compatibility with OSX 10.7.5 (my current operating system) but does not make any mention of the year in which the computer was built. Will I be able to obtain USB 3.0 speeds or would I just be wasting my money? Any insight would be greatly appreciated. Thanks.

    There have been more limitations and choices in support for even the 2008 and earlier.
    Chipsets change, some use drivers and drivers that support 32-bit kernel and a smaller number of users, have hampered choice.
    I was using two Sonnet SATA II controllers, the E2P and the E4P. Those worked and of course speed was fine, as was ejecting, sleep and other features and behavior.  The Allegro has probably changed over the years and there are cheaper alternatives.
    www.xlr8yourmac.com does have readers reports in a database and write-ups.
    It has also been discussed here many many times, and on MacRumors forum for the Mac Pro.
    What is the state of USB 3.0 on Mac Pro?  (  1 2 3 4 5 6 ... Last Page)
    Highpoint can be iffy in support. As to USB2 speeds, only if the device(s) are a factor, and Allegro does not support hubs or non-storage devices (phone, tablet, card readers etc)

  • HT3951 helo   when i want to dollar from the online manager football and need for speed the game , i try to buy but i cannot because they told ( your purchase could not be completed contact itunes store support to complete this transaction.)  pleasr help

    helo
    when i want to dollar from the online manager football and need for speed the game , i try to buy but i cannot because they told ( your purchase could not be completed contact itunes store support to complete this transaction.)
    pleasr help me for that , i can not buy any thing inside the game .
    i wating , thank you
    Email : [email protected]

    Click here and request assistance.
    (75245)

  • V04 and maximum download speed - how do BT get awa...

    I have been a BT Vision customer for only 1 week and all seemed well at first.
    I moved to where I now live on the 1st November and my Total Broadband service was implemented on that date (I have had Total Broadband for many years at my previous address).
    Today I have the dreaded "V04" message and a line sped check reveals a download speed of only 1230 kbps (with an apparent line maximum of 2000 kbps). What the heck is that about? Is this the 21st century or not?
    I live in the middle of a state of the art city development literally next door to the new MediaCity in Manchester (soon to be home to the BBC) so I would have expected line speeds here to be as high as you could have got ANYWHERE
    In addition, how does BT justify selling a product they must KNOW (based on the maximum line speed figure the speed test has thrown up) will not be useable
    If there really are BT people on this forum, I would love some answers and not from someone in a Mumbai call centre who, whilst trying their best, is really just going through the scripted responses
    Another day like this and frankly, BT can shove their box up their nearest junction box!

    I take it from your post that On Demand was working?
    If so and your line speed has now dropped then you need to report a line fault.
    Life | 1967 Plus Radio | 1000 Classical Hits | Kafka's World
    Someone Solved Your Question?
    Please let other members know by clicking on ’Mark as Accepted Solution’
    Helpful Post?
    If a post has been helpful, say thanks by clicking the ratings star.

  • Can the MacBook Pro use 10GBASE-T ethernet cables and achieve internet speeds of up to 10 gigabytes a second?

    I was wondering if I could use a Cat6 cable with my macBook pro and achieve internet speeds up to 10 gigabytes a second without using a Thunderbolt to 10GBASE-T ethernet adapter.

    joshuafromwaterford wrote:
    10 gigabytes a second without using a Thunderbolt to 10GBASE-T ethernet adapter.
    The 10GBASE-T standard allows for max 10Gbit/s. Gigabits, not gigabytes.

  • Will a more powerful processor increase my GMail and Google Apps speed??

    Will a more powerful processor increase my GMail and Google Apps speed??

    I take it that you know the processor in the iMac G4 is not upgradeable. It's soldered to the logic board. The 20" iMac G4 had the fastest process of any G4 iMac--1.25Ghz-- so you're maxed out there.
    Do "About the Mac.." from the the Apple menu to see how much RAM is installed. Sluggishness can be due to too little RAM.
    Sluggish performance can be a too full hard drive. Single click your hard drive's icon then do command i to see the values of Capacity, Available, and Used. the space Available should be no less than 10-15 percent of the vaule under Capacity.
    For comparison, I have a G4 tower with a single 1.25Ghz processor and the same bus speed and video RAM you have, and it is not at all sluggish with anything other than Office 2008, which is sluggish all by itself. My G4 has 1.75G RAM and a bunch of free space on the hard drive.

  • Audio and Video streaming speed to high

    I'm struggling for a couple of weeks to stream fm radio to my BB. It switches over to wap, and right after that the buffer starts filling. I hear a coupke of seconds of normal sound, and then the speed doubles. Anyone knows what i'm doing wrong?

    It is video transmission only.  That is the only example I can find that comes close to what you are trying to do.  Together along with this demo:
    http://www.ni.com/white-paper/13881/en/
    You may be able to piece together what you are trying to do.  Other than that, I don't see any current audio/video streaming examples.  If you pursue this application, don't forget to give back to the community!
    http://www.ni.com/examples/

Maybe you are looking for