I work with a Codility problem provided below, The Fibonacci sequence is defined using the following recursive formula: A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jum…
Tag: performance
java.util.Map values() method performance
I have a map like this with several million entries: I need to get list of values, which could be done by calling java.util.Map values() method. Is Collection of values created every time I call values() method or is it pre-computed from performance perspective? As my Map has several millions elements, I do n…
Snapping Effect in HorizontalScrollView
I want to achieve Snapping effect in HorizontalScrollView i.e when the user scrolls horizontally the item which is most visible (item visible > 50%) comes to the center. I tried to do this using: But the value is not constant even when we do not touch the screen. Here is some part of logcat: I’ve alr…
Performance of JavaFx Gui vs Swing
I wrote two simple programs, both draw the same Sierpinski Triangle: One program was implemented using swing, and one using javafx. There is a very significant performance difference, swing implementation being consistently much faster: (In this test case : Swing over 1 sec. Javafx over 12 seconds) Is it to b…
Can I get “BULK INSERT”-like speeds when inserting from Java into SQL Server?
During my quest to find the fastest method to get data from Java to SQL Server, I have noticed that the fastest Java-method I can come up with, is still 12 times slower than using BULK INSERT. My data is being generated from within Java, and BULK INSERT only supports reading data from a text file, so using BU…
Android – Prevent white screen at startup
As we all know, many Android apps display a white screen very briefly before their first Activity comes into focus. This problem is observed in the following cases: Android apps that extend the global Application class and perform major initializations therein. The Application object is always created before …
Fast and asynchronous way of making multiple http requests in JAVA
I have a program that should make really fast http requests. Requests should be made asynchronously so that it won’t block the main thread. So I have created a queue which is observed by 10 separate threads that make http requests. If something is inserted in the queue then the first thread that gets th…
Java infinite loop performance
I have a Thread that only has to work when a certain circumstance comes in. Otherwise it just iterates over an empty infinite loop: Does it affect the performance when the loop actually does nothing but it has to check if it has to do the calculation every iteration? Only creating a this Thread when needed is…
Increase the java heap space of a certain app
I have an application that I want to run it and gives it more heap memory. I run my application using this command in terminal: home/bin/hadoop jar $pathofjarfile parameter1 parameter2 but I don’t know how to allocate more heap memory when running this application? if anyone could please advise. Answer …
String vs StringBuffer. Tip of IDEA
Intellij Idea offers to replace the following: To: As far as I know it’s less effective (mutable/immutable). So, what’s better? Answer The second one compiles to the same byte-code as the first one, except it uses a non-synchronized StringBuilder instead of a synchronized StringBuffer. So it’…