相关疑难解决方法(0)

如何在Java中编写正确的微基准测试?

你如何在Java中编写(并运行)正确的微基准测试?

我在这里寻找代码示例和注释,说明要考虑的各种事项.

示例:基准测量应该测量时间/迭代或迭代/时间,为什么?

相关:秒表基准可以接受吗?

java benchmarking jvm jvm-hotspot microbenchmark

835
推荐指数
11
解决办法
11万
查看次数

哪个String方法:"contains"或"indexOf> -1"?

以下哪种方法是确定子字符串包含的有效方法?

if (str.indexOf("/") > -1)
Run Code Online (Sandbox Code Playgroud)

要么

if (str.contains("/")) 
Run Code Online (Sandbox Code Playgroud)

java string substring

45
推荐指数
3
解决办法
4万
查看次数

Commons Lang StringUtils.replace性能vs.String.replace

当我比较Apache的性能StringUtils.replace()VS String.replace()我很惊讶地知道,前者是快约4倍.我使用Google的Caliper框架来衡量效果.这是我的考试

public class Performance extends SimpleBenchmark {
    String s = "111222111222";

    public int timeM1(int n) {
        int res = 0;
        for (int x = 0; x < n; x++) {
            res += s.replace("111", "333").length();
        }
        return res;
    }

    public int timeM2(int n) {
        int res = 0;
        for (int x = 0; x < n; x++) {
            res += StringUtils.replace(s, "111", "333", -1).length();
        }
        return res;
    }

    public static void main(String... args) {
        Runner.main(Performance.class, args);
    } …
Run Code Online (Sandbox Code Playgroud)

java

39
推荐指数
4
解决办法
4万
查看次数