Java System Library performance tuning attention points

Source: Internet
Author: User
Tags volatile

For most application development, microsecond optimizations are usually ignored or not, because there are more optimizations, but for the common libraries that are used to develop the provisioning system, most of the operations are usually on characters, numbers, strings, and bytes, and these system libraries are often called very frequently, For example, for a middleware, a single RPC request might involve hundreds or thousands of operations, so fine performance is important at this point.

Final static short finalshort = 120;
static short nofinalshort = 120;
Volatile static short volatilefinalshort = 120;
Final static int finalint = 120;
static int nofinalint = 120;
volatile static int volatilefinalint = 120;
Final static long Finallong = 120;
static long Nofinallong = 120;
Volatile static long Volatilefinallong = 120;
Final static Boolean finalbool = false;
static Boolean nofinalbool = false;
Volatile static Boolean volatilefinalbool = false;
Final static String finalstr = "DOFIDJFE";
static String Nofinalstr = "DOFIDJFE";
volatile static String volatilefinalstr = "DOFIDJFE";
Final static char Finalchar = ' f ';
static char Nofinalchar = ' f ';
volatile static char Volatilefinalchar = ' f ';


public static void Main (string[] args) throws Unsupportedencodingexception {
SYSTEM.OUT.PRINTLN ("Finalshort begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finalshort = = 121) {}
}
System.out.println ("Finalshort end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Nofinalshort begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinalshort = = 121) {}
}
System.out.println ("Nofinalshort end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Volatilefinalshort begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinalshort = = 121) {}
}
System.out.println ("Volatilefinalshort end:" + System.currenttimemillis ());

SYSTEM.OUT.PRINTLN ("Finalint begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finalint = = 121) {}
}
System.out.println ("Finalint end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Nofinalint begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinalint = = 121) {}
}
System.out.println ("Nofinalint end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Volatilefinalint begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinalint = = 121) {}
}
System.out.println ("Volatilefinalint end:" + System.currenttimemillis ());

SYSTEM.OUT.PRINTLN ("Finallong begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finallong = = 121){}
}
System.out.println ("Finallong end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Nofinallong begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinallong = = 121) {}
}
System.out.println ("Nofinallong end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Volatilefinallong begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinallong = = 121) {}
}
System.out.println ("Volatilefinallong end:" + System.currenttimemillis ());

SYSTEM.OUT.PRINTLN ("Finalbool begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finalbool = = True) {}
}
System.out.println ("Finalbool end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Nofinalbool begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinalbool = = True) {}
}
System.out.println ("Nofinalbool end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Volatilefinalbool begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinalbool = = True) {}
}
System.out.println ("Volatilefinalbool end:" + System.currenttimemillis ());

SYSTEM.OUT.PRINTLN ("FINALSTR begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finalstr.equals ("E")) {}
}
System.out.println ("Finalstr end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("NOFINALSTR begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinalstr.equals ("E")) {}
}
System.out.println ("Nofinalstr end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("VOLATILEFINALSTR begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinalstr.equals ("E")) {}
}
System.out.println ("Volatilefinalstr end:" + System.currenttimemillis ());

SYSTEM.OUT.PRINTLN ("Finalchar begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Finalchar = = ' E '){}
}
System.out.println ("Finalchar end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Nofinalchar begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Nofinalchar = = ' E ') {}
}
System.out.println ("Nofinalchar end:" + System.currenttimemillis ());
SYSTEM.OUT.PRINTLN ("Volatilefinalchar begin:" + system.currenttimemillis ());
for (int i=0;i<100000000;i++) {
if (Volatilefinalchar = = ' E ') {}
}
System.out.println ("Volatilefinalchar end:" + System.currenttimemillis ());

}

Finalshort begin:1476275678790
Finalshort end:1476275678837
Nofinalshort begin:1476275678837
Nofinalshort end:1476275678868
Volatilefinalshort begin:1476275678868
Volatilefinalshort end:1476275678915
Finalint begin:1476275678915
Finalint end:1476275678947
Nofinalint begin:1476275678947
Nofinalint end:1476275678978
Volatilefinalint begin:1476275678978
Volatilefinalint end:1476275679025
Finallong begin:1476275679025
Finallong end:1476275679056
Nofinallong begin:1476275679056
Nofinallong end:1476275679087
Volatilefinallong begin:1476275679087
Volatilefinallong end:1476275679119
Finalbool begin:1476275679134
Finalbool end:1476275679165
Nofinalbool begin:1476275679165
Nofinalbool end:1476275679197
Volatilefinalbool begin:1476275679197
Volatilefinalbool end:1476275679259
finalstr begin:1476275679259
finalstr end:1476275679681
nofinalstr begin:1476275679681
nofinalstr end:1476275680246
volatilefinalstr begin:1476275680246
volatilefinalstr end:1476275680642
Finalchar begin:1476275680642
Finalchar end:1476275680673
Nofinalchar begin:1476275680673
Nofinalchar end:1476275680735
Volatilefinalchar begin:1476275680735
Volatilefinalchar end:1476275680775

String is 5-6 times slower relative to char and integer.

Final in addition to objects, the native type can achieve the effect of a/C + + macro at compile time, so it is much better to be able to use native type performance for very frequent operations.

Java System Library performance tuning attention points

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.