| Author |
Improve performance
|
Paras Ahuja
Ranch Hand
Joined: May 22, 2012
Posts: 62
|
|
Hi everyone,
I would like to ask a general question:
Which one is faster: to create a new object every time or to store an object in a file(using serialization) and retrieve it whenever needed.
|
 |
Alexei Kaigorodov
Greenhorn
Joined: Feb 24, 2008
Posts: 17
|
|
|
Unless it is required to make heavy calculations to fill object's content, creation is faster. Note that retrieving from database also includes object creation, and access to database itself requires a lot of processor's cycles.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4901
|
|
Alexei Kaigorodov wrote:Note that retrieving from database also includes object creation, and access to database itself requires a lot of processor's cycles.
Although I agree with you in general, it's worth noting that the whole reason that databases exist is to persist and retrieve data; so, while for an individual object what you say is right, if Paras needs to store lots of objects, a database (NOT a file) is probably the way to go.
@Paras: Either way, serialization, while convenient, is extremely slow. It's more often used with Streams to pass entire objects across a network than as a primary persistence mechanism. And, unless you're dealing with very small amounts of data, a database is probably better than using files - in fact, with a 'wrapped' db like JavaDB it may even be better for individual objects too.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Paras Ahuja
Ranch Hand
Joined: May 22, 2012
Posts: 62
|
|
Well, i only know how to store objects in a file. Let me know how to do the same in database.
Also, another performance related question:
Is it better to import whole packages or just the classes we need to use.
I am making quite a big project and such minute things are affecting my performance (i think)
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10040
|
|
Paras Ahuja wrote:Is it better to import whole packages or just the classes we need to use.
I am making quite a big project and such minute things are affecting my performance (i think)
it's not. All an import statement does is tell the compiler "Hey, when I say 'class', i really mean 'fully.qualified.name.of.class".
So having a lot of imports may slow down your compile phase, it will have ZERO impact on your run-time performance.
(at least, this is what I have read many, many times).
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Ivan Jozsef Balazs
Ranch Hand
Joined: May 22, 2012
Posts: 449
|
|
fred rosenberger wrote:
So having a lot of imports may slow down your compile phase, it will have ZERO impact on your run-time performance.
(at least, this is what I have read many, many times).
You can prepare a test case: two versions of a class, one with fully qualified class names, the other the same but with imports,
and then you can disassemble the resulting classes to verify they are essentially identical.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4901
|
|
Paras Ahuja wrote:Well, i only know how to store objects in a file.
Then life will be SLOW.
Let me know how to do the same in database.
No. It would take far too long. Try the tutorials or (possibly better) get a good book on the subject.
Winston
|
 |
 |
|
|
subject: Improve performance
|
|
|