PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | ||
· Estimate | · 估计这个任务须要多少时间 | 15 | 20 |
Development | 开发 | ||
· Analysis | · 需求分析 (包括学习新技术) | 60 | 90 |
· Design Spec | · 生成设计文档 | 20 | 30 |
· Design Review | · 设计复审 | 30 | 60 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 5 | 5 |
· Design | · 具体设计 | 30 | 30 |
· Coding | · 具体编码 | 180 | 350 |
· Code Review | · 代码复审 | 30 | 40 |
· Test | · 测试(自我测试,修改代码,提交修改) | 30 | 90 |
Reporting | 报告 | ||
· Test Repor | · 测试报告 | 30 | 50 |
· Size Measurement | · 计算工做量 | 20 | 30 |
· Postmortem & Process Improvement Plan | · 过后总结, 并提出过程改进计划 | 30 | 60 |
合计 | 480 | 855 |
刚拿到题目的第一反应是利用正则表达式进行词频统计。 经过正则表达式进行匹配,同时正则表达式匹配空白行,正则表达式匹配ASCII字符。
整个过程的思路是这样子:java
CalMost: 对词频进行排序,返回最多的前10个
CharsCount: 完成对字符个数的统计
LinesCount: 完成对行数的统计
WordsCount: 对单词个数进行统计,同时生成Map
git
/** * @param map the HashMap contain words and amount * @return the top 10 amount of the words and amount in list */ public List<Map.Entry<String, Integer>> mostWords(HashMap<String, Integer> map)
利用VisualVM进行性能分析,如下是执行100000次的结果
github
能够看出主要耗时仍是载输出到文件这里。后续再想办法看看有没有优化的空间。最近时间不够用了正则表达式
/** * @param map the HashMap contain words and amount * @return the top 10 amount of the words and amount in list */ public List<Map.Entry<String, Integer>> mostWords(HashMap<String, Integer> map) { // convert HashMap to list List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet()); // sort by value then by key list.sort(new MapComparator()); return list.size() < 10 ? list.subList(0, list.size()) : list.subList(0, 10); } /** * This class define how to compare the element in list */ private class MapComparator implements Comparator<Map.Entry<String, Integer>> { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return o1.getValue().compareTo(o2.getValue()) != 0 ? o2.getValue().compareTo(o1.getValue()) : o1.getKey().compareTo(o2.getKey()); } }
/** * @param content the input */ public WordsCount(String content) { String[] temp = content.split("\\s+"); String countRegex = "^[a-zA-Z]{4,}.*"; for (String i : temp) { if (i.matches(countRegex)) { sum++; String lowCase = i.toLowerCase(); if (!map.containsKey(lowCase)) { map.put(lowCase, 1); } else { int num = map.get(lowCase); map.put(lowCase, num + 1); } } } }
覆盖率应该算还行吧,每一个方法都有覆盖到。
LinesCount中有个catch中的没有覆盖到。ide
此次看了一些测试相关的东西,以前本身写东西都没有用过单元测试,或者就本身直接print出来,测试几个是否跟本身的预期符合。没有过写单元测试的经历。
经过此次,了解了单元测试的有点,当项目较大时,经过测试更能提早发现问题。
完成做业所花的时间跟本身的预期差距也是比较大的。一开始以为本身一直都陆陆续续有在写Android,作这个应该不会很花时间。后面才发现...Android...Java差异仍是有的,主要缘由仍是本身对Java的掌握仍是不够深。接下来以仍是要花些时间加深对Java的掌握。
本次做业完成的质量,我的并非很满意,由于手头上同时还有很多代码要写但愿赶忙写完,好累好累,因此时间精力并无充分投入,但愿下一次做业能让本身比较满意。性能