小编Ale*_*lex的帖子

Java 11字符串连接性能与Java 8

有人知道为什么在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)

java string performance concatenation

4
推荐指数
2
解决办法
827
查看次数

标签 统计

concatenation ×1

java ×1

performance ×1

string ×1