小编Maa*_*ers的帖子

逐行阅读STDIN的最快方式?

我正在寻找最经济有效的逐行读取STDIN的方法.

第一行是要测试的条件数.以下所有行都是条件(字符串),最多为100 000个字符.

我已经尝试了以下(加上4次90 000个字符的结果:

  • 带有while循环的扫描仪(7255 ms)

    Scanner sc = new Scanner(System.in);
    int numberOfLines = Integer.parseInt(sc.nextLine());
    long start = 0;
    int i = 1;
    while (i<=numberOfLines){
        start = System.currentTimeMillis();
        sc.nextLine();
        Debug.println((System.currentTimeMillis()-start) + "ms for scanner while");
        i++;
    }
    
    Run Code Online (Sandbox Code Playgroud)
    • 结果:
      1. 扫描仪3228ms
      2. 用于扫描仪的2264ms
      3. 扫描仪1309ms
      4. 扫描仪454ms
  • 带有for循环的扫描仪(7078 ms)

    Scanner sc = new Scanner(System.in);
    int numberOfLines = Integer.parseInt(sc.nextLine());
    long start = 0;
    for (int i = 1; i<= numberOfLines;i++){
        start = System.currentTimeMillis();
        sc.nextLine();
        Debug.println((System.currentTimeMillis()-start) + "ms for scanner for");
        //i++;     
    }
    
    Run Code Online (Sandbox Code Playgroud)
    • 结果:
      1. 3168毫秒扫描仪
      2. 用于扫描仪的2207毫秒 …

java optimization performance stdin

20
推荐指数
1
解决办法
5万
查看次数

Java verbose:gc如何读取输出?

我有一个Java应用程序,它有一些性能问题,有人建议我在verbose:gc模式下运行它.这已经完成,但我不知道如何解释日志记录.是否有可能向我解释这一切意味着什么,或建议我如何提高绩效?

输出日志可在以下网址找到:http://pastebin.com/uDNPEGcd

在此先感谢,亲切的问候,马腾

java performance verbosegc

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

performance ×2

optimization ×1

stdin ×1

verbosegc ×1