我正在寻找最经济有效的逐行读取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)
带有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)
我有一个Java应用程序,它有一些性能问题,有人建议我在verbose:gc模式下运行它.这已经完成,但我不知道如何解释日志记录.是否有可能向我解释这一切意味着什么,或建议我如何提高绩效?
输出日志可在以下网址找到:http://pastebin.com/uDNPEGcd
在此先感谢,亲切的问候,马腾