• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to improve the performance of the application in java?  RSS feed

 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite familiar with java but i have to develop a project in java . The algorithm which i wanted to develop is working fine but the performance of my application is too slow . The problem i think is to the cycle for i have used. What i have to accomplish is to perform an algorithm for each byte of the file. This algorithm do some mathematical operation over each byte of the file and to execute it for a large file let say MB it takes me 5 minutes or more. For files of 60 kB it is ok but the larger the file the higher time of execution. I think the problem is because i am performing it byte by byte. I was thinking is there out any way to perform my algorithm for each byte of the file but without going into a for cycle?? Let say i have this class:



So is there out any way how to improve the performance of my application?
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing your algorithm and its implementation it's hard to give you any meaningful input.

edit: If your implementation takes 5 minutes for a 1 MB file, it would certainly seem like there should be room for improvement.

edit2: I find the variable name 'file' misleading. Java has a class File which I typically associate with this name. Seems like a name like 'bytes' would be more appropriate, or something that describes what a byte represents, like 'pixels'.
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have to do operation X for each byte in the array, then a loop is the most practical way of doing that. If your goal is to reduce the running time of the program (there are various kinds of "performance" but it sounds like that's the one you want) then you should look at things which are done frequently and try to reduce their running time. In your case you should look at what I called "operation X" because it is executed thousands or millions of times. Looking at the loop is going to be fruitless because it is only executed once.

By the way there are things called "profilers" which can look at your code as it runs and find out which methods use most of the execution time. You should really start out by finding that out, rather than using guesswork to choose something to improve.
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul Clapham you are right. I want to improve my runtime performance and now that i am thinking deeply i also agree with you and think maybe the operation x is the one which reduce my performance. I do not know if you know much about cryptography but the operation i am using is Shamir Secret Sharing and i evaluate the polynomial based on GF (256). Maybe i should use Horner rule to improve my performance
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
barlet south wrote:@Paul Clapham you are right. I want to improve my runtime performance and now that i am thinking deeply i also agree with you and think maybe the operation x is the one which reduce my performance.

There may also be external things that you have no control over.

For example: if this byte[] really does come from a file, then you will be constrained by the speed that it can be handed to you - and file (or disk, or network) I/O is often a performance bottleneck.

However, one thing that you can do in Java is to use "buffered" classes - BufferedInputStream, BufferedReader, etc - to read files; and they will usually work as fast as your system allows.

Another possibility, if you're on version 8 and depending on what you need to do, is to use streams, because in some cases they can be "parallelized" (ugh), which may make throughput quicker.

HIH

Winston
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Winston Gutkowski it is true and you are right . Anyway i also have used buffered class to read the file . The one i was concerned was the for loop i was thinking the loop is the one which reduce my performance but as i understood from all your helpful comments the problems seems to appear at my operation x
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!