Forums Register Login

How to improve the performance of the application in java?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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'.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
@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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
@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
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 403 times.
Similar Threads
Need help with CS homework please :)
How to read all file at once in string representation instead of byte one
"Protect" a pen drive from malware using java code - please review my (working) code ?
Boxing, unsigned bytes, and how to process them at various speeds.
How to insert a same size for all files in java?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 20:24:50.