I am working on a Sudoku solver in school, and we have a little competition. Now my algorithm is pretty fast in the first run (about 2.5 ms), but even faster when I solve the same puzzle 10,000 times (about 0.5 ms for each run). Of course, this time depends on the puzzle being solved. I know that the JVM does some optimization when the method is called several times, and this is what I suspect is happening.
I donβt think that I can further optimize the algorithm itself (although I will continue to search), so I was wondering if I could reproduce some of the optimizations performed by the JVM.
Note: compiling to native code is not an option.
Thank!
Edit: All these parameters of the virtual machine are good, but are not really βlegalβ in the competition of algorithms, since everyone can use these parameters and increase productivity. I am looking for code optimization.
tl; dr : no, most optimizations performed by the JVM cannot be expressed in Java bytecode.
At its core, Java byte code defines your code at a very high level.
This is by design and is one of the reasons why the JVM can perform all these optimizations: the byte code describes the operations at a relatively high level and leaves the actual data on the JVM's execution.
.
, JVM , , , ArrayIndexOutOfBoundsException (. VM Spec 2.5.14).
ArrayIndexOutOfBoundsException
JVM , , (, , JVM ).
, , .
, . JavaWorld . .
. , .
"", JIT ,
-XX:CompileThreshold=20
, . ( ) .
, . , "" , .
"" , , `System.gc();
JVM JIT (Just-In-Time): - Java . , , . , , - , - 10 000 , , JVM, , , , , .
, , JVM . (edit: , mdma - -XX).
-XX
Sun JVM: JVM, , , JVM, , .
JVM :
java -server com.mypackage.MyProgram
, , , 64- Sun Java Windows JVM .
-, , , - , , . .
, ;)
, , , (, ). (SPEC ..) ( ), , , , JIT ..
, , -, 2,5 , - JVM , Windows, , , System.currentTimeMillis(). , ... 30 60 .
- , . FYI , . .
, , :
1) , . 2
int i = 10 / 2; // division by 2 i = 10 >> 1; // does the same
2) , . int over Integer
3)
4) , . + = 2 = + 2
5) , ,
for (int i = 10; i >= 0; i--) { System.out.println(i); } (only useful if you can compare against zero)
6)
Source: https://habr.com/ru/post/1747851/More articles:Create random number from fix Set of numbers in iphone - c ++.tex files not found when placed in a folder declared in TEXINPUTS - variablesJavascript instanceof & typeof in GWT (JSNI) - javascriptWhat to throw in a C ++ class wrapping a C library? - c ++Search for full text index for 'C #' - sql-serverHow can I emulate / fake / import an SD card with a live connection to a computer? - hardwareto find and replace values ββin a flat file using PHP - phpHtmlAgilityPack gives problems with distorted html - c #jQuery: what if i don't have a mouseleave function? - jqueryJava instrumental libraries - javaAll Articles