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的掌握。
本次做業完成的質量,我的並非很滿意,由於手頭上同時還有很多代碼要寫但願趕忙寫完,好累好累,因此時間精力並無充分投入,但願下一次做業能讓本身比較滿意。性能