罗杨美慧 20190919-3 效能分析

作业要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/7628]

要求0 以 战争与和平 作为输入文件,重读向由文件系统读入。连续三次运行,给出每次消耗时间、CPU参数。

运行方法

ptime wf -s < war_and_peace.txt

第一次运行:

第二次运行:

第三次运行:

CPU参数:Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz 2.808 GHz

第三次运行时间:1.283s

第三次运行时间:1.298s

第三次运行时间:1.276s

平均运行时间:1.285s

要求1 给出你猜测程序的瓶颈。

由文件重定向读入时遍历文档消耗大量时间,来实现字母大小写和字符与符号的转换。

 public static void TxtRedirct() throws Exception {
        Scanner readerScanner = new Scanner(System.in);
        List<String> lists = new ArrayList<String>();  //存储过滤后单词的列表  
        String readLine = null;
        while (readerScanner.hasNextLine()) {
            readLine = readerScanner.nextLine();
            String[] wordsArr1 = readLine.split("[^a-zA-Z]");  //过滤出只含有字母的  
            for (String word : wordsArr1) {
                if (word.length() != 0) {  //去除长度为0的行  
                    lists.add(word);
                }
            }
        }
        readerScanner.close();
        StatisticalCode(lists);       
    }

要求5 程序运行时间。

供老师测试代码地址:https://e.coding.net/lymh/wf1.git

原文地址:https://www.cnblogs.com/lymh/p/11568004.html