Faster alternative to vectors?

I have a file with 25'000 lines of text. I read in line by line, placing each line as a String Element into a Vector. Later I read out again all or parts of those Vector Elements.
I found that Vector.add() is too slow to process such a hughe number of lines; it's lasting some minutes.
So my question; Is there a faster alternativ to vector i could use? any ideas?

Here's why setting initial capacity/increment helps. What's stored in the Vector internally is an array of references to each Object contained within the list. Let's say the initial capacity is 10. To add the 11th element, it's got a have an internal array big enough, so it has to allocate a new array with a bigger size, copy the original references over, then add number 11 to the array. The increment determines the number of extra slots it adds with each reallocation.
Also, Vector is thread safe, with slows it down.
Either use ArrayList, which is not thread safe, and use a high initial capacity and step increment. Another option is to use LinkedList, which doesn't have the allocation problem. The catch to using it, though, is that if you wish to access an element by index, it's much slower. If you want to iterate though the whole list, get an Iterator object off the list.

Similar Messages

  • Alternatives to Vector

    I'm developing an application that needs to have objects that contain multiple objects. I've been using Vectors because I don't know what size the final "arrays" are going to be as I'm pulling values off the database.
    I am currently experiencing some performance problems. I've checked the database queries and they seem to be very fast.
    This leads me to believe that the problem lies in the Vector class.
    I did a check in the javadoc and found Collection, List, LinkedList, etc...
    Does anyone out there have a preference in the alternatives to Vector? What are the pros and cons in using these alternatives?
    Thanks in advance.

    Those suggestions will speed things up somewhat. But the overhead in resizing is nothing compared to the synchronization overhead incurred with using Vector. Vector is there to fill a hole, It's a Thread safe, indexed, expanable list...It's just plain slow. If you have no idea what I'm talking about...
    Vector code:
    public synchronized Object get(int x) {
        // access x and return;
    }Array List Code:
    public Object get(int x) {
       // access x and return;
    }The ArrayList code is over 3 times faster per method call, because it is not synchronized. If you don't need a concurrent data structure. ArrayList will increase your speed a whole lot.

  • Faster alternative to cfcontent for large file downloads?

    I am using cfcontent to securely download files so the user
    can not see the path the file is stored in. With small files this
    is fine, but with large 100mb+ files, it is much, much slower than
    a straight html anchor tag. Does anyone have a fast alternative to
    using cfheader/cfcontent for large files?
    Thanks

    You should be able to use Java to handle this, either through
    a custom tag or you might be able to call the Java classes directly
    in Coldfusion. I don't know much about Java, but I found this
    example on the Web and got it to work for uploading files. Here's
    an example of the code. Hope it gives you some direction:

  • Faster Alternatives to Bridge CC

    I only use Bridge as a photo browser--I use Lightroom/Photoshop for any real work.
    But sometimes I just want to browse a folder and be able to zoom and/or open in Photoshop.
    So I do use Bridge in this very limited way.
    But CC is so slow as to be non-functional. [running Mountain Lion on Core i7 with 16GB RAM]
    I use a lot of CC software--Lightroom, InDesign, Photoshop, Premiere Pro, Audition--none of it crawls like this.
    So, my question is--is there a faster, professional [i.e. NOT Picassa] photo browser that I can replace Bridge with?
    [I have a lot of photos on archived on several drives]
    Obviously, there's Photo Mechanic...which I may go to if I have to, especially on location. But for now I was hoping for something a little less expensive. Plus it duplicates a lot of Lightroom does, which is my main workhorse.
    I just want a photo browser.
    Thanks,
    Margot

    This is a late reply but hopefully it might help you or someone else.
    For those who don't want to read my mammoth post this is the condensed version:
    Bridge/Lightroom = good but painfully slow.
    Alternatives for PC:
    ACDSee Pro ( I use Pro 6.0)
    Faststone - Free and fast.
    Alternatives for Mac:
    ACDSee Pro ( I use 2.0)
    Xee - Free and fast, but few features
    On to the full version.
    First, my experience with Bridge/Lightroom then further down my solution:
    Bridge/lightroom both have good file management tools and lots of other features but as you've discovered they are slow.
    I've used Lightroom (sparingly) since 3.0 up to 5.0. Only reason I have the latest version now is because i'm subscribing to Adobe CC and I hoped for some improvements regarding speed and workflow but was disappointed. Still slow image to image rendering and still no way to simply browse files without importing them. (or have I missed something?)
    Main thing is still that it's slow.
    Bridge has been around for a long time now and I've tried using it since my first version which shipped with Adobe Master Collection CS3. I've jumped on every single update Adobe has thrown at it but it is still painfully slow when browsing/viewing images and forget about selecting images based on sharpness as it simply cannot handle proper scaling to screen size on the fly. It has to create preview files first, which I have still not managed to set up in spite of an excess of 100 hours research/re-install/cache purging/mucking with settings etc..
    My experience tells me that the only way to accurately gauge focus in Bridge is to zoom in 100%, something that also takes extra time especially with raw files.
    I really want to love Bridge since that would mean my Adobe CC subscription would handle everything I need, but no, I simply cannot get around the fact that Bridge is too slow to be efficient.
    For the record my systems are not slow, the specs are:
    PC:
    QuadCore i7 2.8GHz
    12GB RAM
    120GB SSD system drive
    Seagate 3TB 7200rpm photo drives
    Eizo 24" flat monitor (don't have the model nr right now but it's a S-PVA panel with good colors)
    Mac:
    Macbook Pro Retina 15"
    2.6 GHz i7
    16 GB Ram
    256GB SSD
    3:rd party solutions I use/used that you might give a try:
    My first choice is ACDSEE - I currently own ACDSEE Pro 6.0 for PC and 2.0 for Mac. I mainly use it to go through my memory cards during import and for that it is MILES AHEAD Lightroom/Bridge.
    There is a decent Categories feature that I sometimes use to keep track of where certain types of images are. For example I've created sets of categories for different clients to keep track of my best images for each client.
    I usually go through my memory cards and simply hit CTRL+B to save to save selected photos into the image basket, this gives me a virtual selection that I can choose to copy elsewhere or perhaps open in Photoshop straight from the memory card.
    It also serves as a blazing fast image viewer, it handles most image formats including jpg/png/gif/psd etc. Best of all, it's REALLY FAST compared to Lightroom and Bridge. It even handles quite big .PSD's however the bigger they get the longer it takes obviously.
    There are key differences between the PC version and Mac version with the PC version being better according to me. One example: The PC version uses two different keyboard shortcuts for the virtual "Image Basket", CTRL+B to add images, ALT+X to remove them from the basket. The Mac version(2.0) only has a "Tag" function where adding/removing images from the tagged list is done with the same shortcut which means you have to exit fullscreen in order to be 100% sure you have added/removed the tag. Also I had to reassign the shortcut because the standard one did nothing.
    I've used ACDSee on the PC about 7 years, it's been really buggy at times, most notably known for "ragequitting" on you while browsing images but the last 3 versions or so have behaved really well. I have still experienced errors forcing me to shut it down but it is now a rare problem and I prefer that risk over the inexcusable slow Bridge/Lightroom. Pro 2.0 is my first experience with it on Mac and it still needs some tweaks but some of my gripes are partly related to getting used to the Mac interface.
    Free alternatives that I've used and recommend:
    For PC I would say Faststone is a really good option, it's fast, reads most image formats, has a tagging function which gives a graphic que wether or not the image is tagged (small pink square appears in the upper left corner if I remember correctly). It has lots of features easily accessed in fullscreen by simply moving the cursor to either side of the screen. Oh and it displays the images way sharper than Bridge/Lightroom without the need to zoom in 100%. Just as with ACDSee it's often possible to determine the sharpness of an image with the image fitted to the screen size, without going 100%.
    For Mac I initially wanted a Faststone alternative since ACDSee wasn't available at first. My research led me to "Xee", a free image viewer that works well although lacks thumbnail view and has nothing equivalent of the Image Basket or tag function for ACDSee.
    Ok, I think I've done my share of typing today, I hope someone finds this information useful.
    If you read this Adobe; C'mon... shape up Bridge and Lightroom already, you've had many years to get it right but alot of users still see poor performance in those otherwise great programs.

  • Faster alternative to Math.random()?

    hi,
    i have profiled a mini-game i've written and found that calls to Math.random are taking up a good proportion of the time (5%). The source for Math.random() is     public static double random() {
       if (randomNumberGenerator == null) initRNG();
       return randomNumberGenerator.nextDouble();
    }which is exactly as expected.
    I don't need any statistical guarantees about the randomness (just need to add some noise to some moving entities paths), so was wondering if there are any neat tricks to do this faster..
    thanks,
    asjf

    Another alternative is to pregenerate several 1000 random numbers,
    stick them in an array, and just cycle through the array. actually, might do that! (do need doubles half the time, but will convert the others to ints)
    otherwise have found this which looks v. promising:
    http://www.honeylocust.com/RngPack/

  • Better and faster alternative for count(*)

    I want to check whether empno=1234 exists in emp table
    Currently I am using in proc
          select count(*) into cnt from emp
                         where empno=1234
        if cnt>1 then exists otherwise no exists.
        Is there any better way to do the same.?

    user11253970 wrote:
    I want to check whether empno=1234 exists in emp table
    Is there any better way to do the same.?http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1525380674899
    select count(*)
      from dual
    where exists ( select NULL
                      from emp
                     where sal = 5000 );Faster still is to not count at all
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1525380674899#34907832120350
    Just process the data and take appropriate action if nothing was processed.

  • Faster alternatives to iPhoto?

    Hey all,
    My iPhoto is really, really slow.
    Can anyone recommend some alternative photo management software?
    Thanks!
    Alec

    Alec:
    A couple of questions. Are you operating iPhoto with all of the rolls open and how much free space do you have on your HD?
    As for other alternatives I use iView MediaPro, a professional media management application, which can handle not only image files but audio, movie, pdf, html and fonts. This page describes its features.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.

  • A faster alternative to an AT MIO 16 DE10?

    I am currently using an AT MIO 16 DE 10 DAQ card I am using 24 digital and 8
    analog channels and the two GPCTRs. This card will go up to 100ksamples/s.
    This sample rate is divided between the number of channels I use for an
    acquisition. I want to use all 16 analog inputs in this card. Is there a
    functionally equivalent card that will give faster sample rates?
    If the events I am sampling have a frequency of 5kHz am I right to assume I
    need at least to sample at 10kHz per channel? This means I need a card that
    will sample at least at 160ksamples/s? Would I be better of oversampling 4
    times? Is there a formula to determine optimum sampling rate?
    Does multiplexing mean that if I sample each channel at 1000 samples
    per
    second by the time I read channel 15 I will be reading it 16 ms after I read
    channel 0? Is there a way around this delay?
    Thanks
    Luis

    Nyquist theorem says that you have to sample at least 2x the frequency of the incoming signal to prevent aliasing. However, if you aren't just trying to avoid aliasing, but also want an accurate representation of the waveform, you must sample at MUCH higher than that. There isn't an equation for that, it just depends on the input signal and what shape it is. Usually for normal waveforms like sinusoidal, 10 times over sampling is recommended.
    As for multiplexing, it depends on your board. For the one you have, yes, if you read 15 channels at 1000 S/s then the board is running at 15 kHz and channel 15 is read roughly 1 ms away in time fom channel 1. If you need simultaneous sampling, NI provides simultaneous sampling DAQ boards(6110E, 6111E) and a connector bl
    ock to do simultaneous sample & hold (SC-2040).
    As for recommending hardware, it sounds like you will need to go to two cards. NI doesn't have a faster MIO board that has 24 digital lines. You can get a 24 line DIO board (6503) really cheap though. Then for your MIO board, it will depend on if you need simultaneous sampling. The 6110E has simultaneous sampling and is really fast (5MS/s), so it would probably be best.
    In the future, you should submit your questions like this to the Measurement Devices->Multifunction I/O section of Developer's Exchange instead, or call National Instruments so our sales representatives can help you with your hardware selection.
    Best Regards,
    Chris Matthews
    Measurement Studio Support Manager

  • Faster alternative to python-vpython

    I started writing a simple python script for specific 3D visualization needs, using python-vpython. I would like to switch to something more efficient, especially at start-up, as importing visual requires already >2s. Having programming experience only with simple langages (Python, C, Oberon) and no experience at all in graphics, I wonder if someone could give me advice, as I just need something very simple. Thanks.

    You should be able to use Java to handle this, either through
    a custom tag or you might be able to call the Java classes directly
    in Coldfusion. I don't know much about Java, but I found this
    example on the Web and got it to work for uploading files. Here's
    an example of the code. Hope it gives you some direction:

  • Vector or ArrayList?

    Hi
    The J2ME-Polish framework provides an implementation of ArrayList. I am concerned in our project about the resource usage. Does anybody of you has experience with the ArrayList? Does it use less resources than the Vector?
    Kind regards
    Michael

    Hi
    The docs from J2ME Polish state that "de.enough.polish.util.ArrayList offers a fast alternative for Vector." I don't think though you would notice any difference when using one or another; you would have to make heavy use of this classes, which is not indicated in J2ME.
    I don't know if we can apply the J2SE concepts for this two classes, but you should read this article and decide what to use: http://www.javaworld.com/javaworld/javaqa/2001-06/03-qa-0622-vector.html
    Mihai

  • How does flash output vector input?

    I'm somewhat of a noob here, so please forgive my ignorance.  I tried to google the answer to my questions, but probably not using the right terms.
    So my questions are these:
    - Is there any advantage to using vector elements in flash projects, or do they just get rasterized in the swf creation process?
    - If you use vector instead of raster art, can you scale your swf infinitely large (theoretically) without degradation?
    - Will vector art result in a smaller swf size?  Will it take less processing power to play?
    Thanks!

    1. Vector graphics are generally the best option you have in a flash movie and keep your swf very low in file size thus faster loading in browser. They do not get rasterized when published into a swf file.
    2. Yes, vector graphics can be scaled infinitely without degradation as they are not resolution dependent.
    3. Generally file sizes of swf are low when using simple vector graphics but it really depends on the complexity of the vector graphics. Flash uses mathematical equations of lines and curves to reconstruct the graphic as it is rescaled. So size and processing speed would largely depend on how complex your vector graphics are made. If you have graphics with alot of curves, corners, lines, etc, your file size will increase as you need more bytes for functions ( f(x) ) to reconstruct the graphic, consequently, more processing time/power is required. There are times raster (bitmap) graphics are a better alternative over vector graphics and there are times when you it is better to convert your bitmap graphic to vector (Modify -> Trace Bitmap) when it only uses a few colors and curves/corners. You will need to experiment and find which works better for you.

  • Better alternative to header lines, use of logical database, field-symbols

    Hello experts,
    I am wondering if theres a better and faster alternative than declaring a header line for an itab. are work areas faster?
    What is the use of logical database? can you please give me an example on how to use it in reports.
    how do I use field-symbols? I am confused on how it works.
    P.S. I recently installed SAP netweaver preview abap edition
    in my home PC and I am wondering if I could practice BDC, user exits, etc. If so, how?
    Again, thanks for all your help since I'm kinda new to ABAP.

    I always use this...It uses header lines, but at least is smaller -:)
    <b>DATA: BEGIN OF MY_TAB TYPE STANDARD TABLE OF BKPF WITH HEADER LINE.</b>
    For logical databases, you can check my blog...I always use LDB for HR programs -:)
    <a href="/people/alvaro.tejadagalindo/blog/2006/02/19/how-to-deal-with-hr-payroll-reports:///people/alvaro.tejadagalindo/blog/2006/02/19/how-to-deal-with-hr-payroll-reports
    LDB's provides a lot of information, because they gather it from a lot of different tables...
    A Field-Symbols is like a pointer in C++, like an alias for a variable...Here's a small example...
    REPORT Z_ATG_DUMMY.
    FIELD-SYMBOLS: <F1>, <F2> TYPE I.
    DATA: TEXT(20) TYPE C VALUE 'Hello, how are you?',
          NUM TYPE I VALUE 5,
          BEGIN OF LINE1,
          COL1 TYPE F VALUE '1.1e+10',
          COL2 TYPE I VALUE '1234',
          END OF LINE1,
          LINE2 LIKE LINE1.
    ASSIGN TEXT TO <F1>.
    ASSIGN NUM TO <F2>.
    DESCRIBE FIELD <F1> LENGTH <F2>.
    TEXT = 'CHAU'.
    WRITE: / <F1>, 'has length', NUM.
    WRITE: / TEXT, 'has length', NUM.
    ASSIGN LINE1 TO <F1>.
    ASSIGN LINE2-COL2 TO <F2>.
    MOVE <F1> TO LINE2.
    ASSIGN 'LINE2-COL2 =' TO <F1>.
    I just can't install SAPNWSP...I only got MiniSap...But I got all the development enviorment...Don't know about the User-Exits...Actually I don't think so...Because those "mini" systems doesn't come with any functional module.
    Greetings,
    Blag.

  • Does vector reduces performance

    Hi,
    it is said that vector is serializable and thread safe
    so it is slow
    ny doubt is if we declare and use vector in a local method then it is not shared with others does still the fact that vector is serializable reduces performance
    is using arraylist better
    i have seen code of many people using vectors
    if vectors are not to be used we have to be careful
    about vectors is using arraylist better than vector
    for same functionality or which is better to use
    if requirement is to store string array which can
    extend to any number of items

    Hi,
    Vectors are extremely slow, due to it being synchronized. An ArrayList is a lot faster than a Vector, but if possible, I'd look at just a plain old array. Arrays are extremely faster than both ArrayList or a Vector. The problem is that arrays don't automatically resize. So it really depends on your design. If you do end up going with a Vector, don't use an Enumeration of Iterator to iterate over the Vector. A lot of unnecessary objects are created, etc... Get the size of the vector at use a simple loop, which is more compact and quicker....
    /rick

  • Vector. Point .sortOn()? How to make a compare function?

    Okay in AS2 I had an array of Points. And I sorted it like this: myArray.sortOn(["x", "y"],[Array.NUMERIC, Array.NUMERIC]);
    I was changing the code over to AS3 and I thought I would change my array into a Vector of Points. But then I realized there isn't a sortOn method for Vectors.
    The sort method takes a compare function and I think I have that working. But I was wondering if there is a better or cleaner way of writing compare functions? This is new to me.
    function compare(p1:Point,p2:Point):Number {
    if (p1.x>p2.x || (p1.x==p2.x && p1.y>p2.y)) {
    return 1;
    } else if (p1.x<p2.x || (p1.x==p2.x && p1.y<p2.y)) {
    return -1;
    return 0;

    there's no substantial difference but in my tests (in cs4,as3) the array.sortOn() was slightly faster:
    var v:Vector.<Point>;
    v = new Vector.<Point>();
    var lengthV:uint=1000000;
    for (var i:uint=0; i<lengthV; i++) {
        v.push(new Point(Math.round(i*Math.random()),Math.round(i*Math.random())));
    var startTime:uint = getTimer();
    v.sort(f);
    trace(getTimer()-startTime);  // ~4700
    var a:Array = [];
    for(var j:uint=0;j<lengthV;j++){
        a.push(new Point(Math.round(i*Math.random()),Math.round(i*Math.random())));
    startTime = getTimer();
    a.sortOn(["x", "y"],[Array.NUMERIC, Array.NUMERIC]);
    trace(getTimer()-startTime);  // ~3500
    function f(p1:Point,p2:Point):Number {
        if (p1.x>p2.x || (p1.x==p2.x && p1.y>p2.y)) {
            return 1;
        } else if (p1.x<p2.x || (p1.x==p2.x && p1.y<p2.y)) {
            return -1;
        return 0;

  • Dwb is dead - What's your alternative?

    According to the wiki:
    https://wiki.archlinux.org/index.php/Dwb
    As of this October 2014, dwb is no longer being maintained. Does anyone have any suggestions on a fast alternative minimal browser that navigates through keybindings?
    Last edited by cynicalpsycho (2014-11-02 15:09:49)

    I just switched to surf
    I really like the way you can extend the browser through simple shell scripts that manipulate dmenu (bookmarking, smart-searching...).
    Plus its super small and fast.
    On the other hand, its ultra-minimal. It follows links and displays web-pages. Thats it. Everything else is hacked on.
    Last edited by captaincurrie (2014-11-02 18:00:35)

Maybe you are looking for

  • Multicolum​n listbox value change and mouse up event in one case of event structure

    Hello All, Am facing two problems: 1. I have two multicolumn events, one is value change for deleting the rows of Multicolumn listbox and another one is mouse up for sorting the columns. But I can't combine both the events in one case. And if I creat

  • Appending fields to LIS

    Hi, I am new to SAP. I have to fetch data from billing tables for which i am using LIS structures. But there are few more filed on which i need to report on which are in delivery and sales tables. Can I append these fields to the LIS strucuture using

  • SAP_HR Support Pack Problem

    Hello, I am trying to apply the year-end support packs for SAP_HR (SAPKE50023 - SAPKE50026).  I get so far with SPAM, but then I get the following error: Error in phase: IMPORT_PROPER, Reason for error: TP_STEP_FAILURE.  I applied the latest TP versi

  • OSB routing URI

    Hi, I need to replace element <To> in <soap:Header> in proxy service with endpoint URI of business service, which is beeing called (using Route). At first I just used Replace action, but of course, we will need different values for development and pr

  • ITunes keeps prompting me to reenter the security code for my credit card each time I make a purchase

    ITunes keeps prompting me to reenter the security code for my credit card each time I make a purchase, saying my Windows 7 PC is a new device. However, the PC is on iTune's list of authorized devices for downloads. What's causing this? I do block coo