"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Well, what are you doing in the while loop? An empty loop would take almost no time - I just tested and it takes less than 10 milliseconds to increment a counter 40000 times, on my system. Calculating a sine function 40000 times takes 180 msec. So you really need to look at what operations are performed inside the loop - they make all the difference.
Originally posted by moor:
while(rs.next())
{y = rs.getInt("x");
// z is a vector
z.addElement( new Integer (y);
}
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
So you are reading 40000 rows from a database??? You don't *really* *need* all of them, do you?
"I'm not back." - Bill Harding, Twister
To be honest, my knee-jerk reaction is "I don't believe you". If you are shifting that kind of data to the client, your users wouldn't be upset by a mere 6 seconds delay. If you're not shifting that kind of data, needing to create 40,000 objects to generate a single response looks like an architectural problem rather than a mere performance problem.Originally posted by moor:
Yes!. I need to add 40,000 elements in to my vector.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Senior Software Engineer, IBM
author of: Practical Java
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Some numbers on my machine: to create 40K different Integer objects and put them in a Vector takes 60 ms. For an ArrayList, 61 ms. And for a LinkedList, 80-90 ms. With presizing, Vector and ArrayList go down to 40 ms. (Presizing is not possible for LinkedList.) So, I'm surprised LinkedList didn't do better - I guess it's really only good for doing insertions and deletions internal to the List. If I modify the code to insert the Integer objects at the beginning of the list rather than the end, LinkedList performance remains the same, but Vector and ArrayList skyrocket to over 8000 ms. (Since they must recopy the entire internal array to shift positions by one, on each insert.) Worth remembering if you ever need to insert or delete somewhere other than the end of a list.
Anyway though, assuming that moor is not inserting entries to the begginning of the list , the times here are all pretty negligible compared to 6 seconds - so the problem is probably elsewhere, as expected. Focus on eliminating the need for the huge ResultSet if possible.
Originally posted by CL Gilbert:
ArrayList is not synchronized. Why does it take longer to perform its operations on your computer than Vector (synchronized) does?
When you add more things than will fit in a Vector or ArrayList, they create a new underlying array (by default it doubles with a Vector and increases by 50% with an ArrayList), then copy all of the elements from the old array to the new array.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
So, ArrayList will more often have to resize.
Originally posted by CL Gilbert:
[...] Its hard to believe.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by moor krish:
Hence can you give any suggestions on how to reduce time spent in accessing the resultset.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"I'm not back." - Bill Harding, Twister
dan moore, infomatiq ltd.<br />email dan@infomatiq.co.uk<br /><a href="http://www.infomatiq.co.uk" target="_blank" rel="nofollow">http://www.infomatiq.co.uk</a>
Originally posted by Ilja Preuss:
So you are reading 40000 rows from a database??? You don't *really* *need* all of them, do you?
Originally posted by Andy Brookfield:
I once wrote a piece of code to display "heart rate variability (HRV)" ... basically I would retrieve a whole day or weeks worth of heart-beat information then dynamically generate a GIF image of the heartbeats... 100K+ records / individual / day!!! ...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Everyone is a villain in someone else's story. Especially this devious tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|