有人知道为什么在Java 8和Java 11上运行此代码时会得到如此不同的性能吗?
在不使用任何运行时标志的情况下,与Java 8相比,此代码在Java 11下的运行速度明显慢得多。
import java.util.Date;
public class PerformanceExperiment {
public static volatile String s = "";
public static void main(String[] args)
{
System.out.println("Starting performance test");
String s1 = "STRING ONE";
String s2 = "STRING TWO";
long now1 = (new Date()).getTime();
for (long i = 0; i < 1_000_000_00; i++)
{
s = "abc " + s1 + " def " + s2;
}
long now2 = (new Date()).getTime();
System.out.println("initial block took " + (now2 - now1) + …Run Code Online (Sandbox Code Playgroud)