• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Improve performance

 
Paras Ahuja
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9490
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paras Ahuja
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9490
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic