BUAA Advanced Software Engineering

Project:  Individual Project - Word frequency program

Ryan Mao (毛宇)-1106116_11061171

Implement a console application to tally the frequency of words under a directory (2 modes).

1)  Before you implement this project, Record your estimate about the time you WILL spend in each component of your program.

Before I started, I split up the assignment into three parts based on my comprehension of the project:

Firstly, I would have to design my approach to the problem (words frequency tally), I decided to divide the whole process as below:

  1. Traverse the directory: A function which is capable of visiting all the files/subfolders under the specific directory. I chose to do it with the algorithm of breadth-first traverse.

Since traverse the directory cannot be achieved without Windows API (as far as I know), I planned to spend half an hour to finish the study of the API.

  1. Statistics: A module used to record how many times a certain word has been read. Factors including the mode, the case and so forth will be taken into consideration. Before I started, I could not tell the details of it, I planned to spend two hours on this part.
  2. Sort&&Output: The process compasses rank the records according to the requirement mentioned. With the assistant of the library “algorithm”, I guessed I could finish it half an hour.
  3. Debug&&improving the performance: In this section, the time is rather unpredictable, thus I planned to spend less than 2 hour on it.
  4. Blog: 1.5 hours.

In conclusion, to finish the assignment, 6.5 hours was estimated.

2)            After you had implemented this project, record the ACTUAL time you spent in each component of your program.

Actually, I spent about 10 hours on this assignment. For each component:

1. 2 hour (Traverse the directory)

2. 2.5 hours (Statistics)

3. 1.5 hour (Sort&&Output)

4. 2.5 hours (Debug&&improving the performance)

5. 1.5 hours (Blog)

3)      Describe how much time you spent on improving the performance of your program, and show a performance analysis graph (generated by VS2012 performance analysis tool), if possible, please show the most costly function in your program.

I did not spent much time on debugging (about 40 minutes), but I spent more time on Improving the performance (1 hour and 50 minutes)

In this case, I use a folder (5MB), which includes 25 English novels.

graph:

Summary

Function Details

Trace the result to find the most time-consuming part: (As below)

It shows that the function used to traverse the files costs the most time (It’s quite surprising since I thought it is the easiest part!)

Let’s go deeper!

Thus, the result is quite obvious that the function statistics used to analyze each file costs the most time.

Deeper…

The result is obvious We should make some improvement on the red parts of the source code.

Analysis

About I just mentioned,

            if(low_first_table.count(temp)==0)//判断是否第一次出现

       {

         low_first_table[temp]=word;

       }

       //统计

       count_table[low_first_table[temp]]++;

Undisputedly, it would be better for me to use the function “find” instead.

Also, about the second part, it would be better if I can store the value of low_first_table[temp] in advance to avoid redundant visits.

So it should be like this:

       if(low_first_table.find(temp)==low_first_table.end())//判断是否第一次出现

       {

         low_first_table[temp]=word;

         count_table[word]++;

       }

       //否则按照其存储结果来统计

       else

       {

         count_table[low_first_table[temp]]++;

       }

Let’s take a look at another possible place to make an improvement: rank.

Firstly, because the structure “Vector<>” is said to have the best capacity allowing random-data-access, indicating that it is right to use Vector under this circumstance. (From C++ Primer. P287).

Secondly, the function “std::sort” is described in document to have a perfect time complexity () for sorting algorithms.

Third, sorting is indispensable due to the requirement.

Thus it would be rather tricky to make an improvement on it.

The Latter Graph (After improvement) is:

It’s not very obvious, but we can still observe the improvement:

3)            Share your 10 test cases, and how did you make sure your program can produce the correct result. (Programs with incorrect result will get 0 points, regardless of speed)

My test cases are designed to contain several “exceptional situation”,includes:

  1. Empty folder (obvious)
  2. Empty file (obvious)
  3. Same words with different upper/lower case. Like “Hello” “hello” “heLLO” .etc.
  4. Same words with different ending numbers. (To test extend mode) Like Windows98, Window99, Window8. Etc.
  5. Words separated with non-alphanumerical char as delimiter. Like: Hello~!!World!****China~~I)()()(Love^&^&You
  6. Different Words with the same frequency. (To test the “sort” function)
  7. String with 3 or less letters. Like Hi, My. Etc
  8. String starts with number. Like 123Hello
  9. String separated with numbers. Like humo99rous.
  10. A large amount of test case. As below: (To see if the program will collapse)

Besides, I also download the Rost English Words Counter From the Internet to compare the result with mine.

5)      Describe what you had learned in this exercise.

In this exercise, I planned to solve the problem in 6.5 hours. However, it took me almost ten hours. I was surprised to learn how unpredictable the software engineering is. Thus, in the sequent studies, I would try to improve my ability of making plans which is considerate and feasible. It would be hard since it requires experience and a broad knowledge on this field. Anyway, I would try my best to learn this course well.

What’s more, I also learned how to use the Performance Analysis feature in Visual Studio 2012. It’s an awesome tool for developers to make improvement on their projects. I would use it more frequently in future.

Finally, I also learned that it is important to understand clearly the user requirement of it. In this case, I misunderstood the word “delimiter” and waste a lot of time on debugging. So, the next time, I would make sure what the requirement really means.

Thanks!

Individual Project - Word frequency program-11061171-MaoYu的更多相关文章

  1. Individual Project - Word frequency program by HJB

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;us ...

  2. Limeng:Individual Project: Word frequency program -BUAA Advanced Software Engineering

    11061190-李孟 Implement a console application to tally the frequency of words under a directory (2 mod ...

  3. Individual Project - Word frequency program - Multi Thread And Optimization

    作业说明详见:http://www.cnblogs.com/jiel/p/3978727.html 一.开始写代码前的规划: 1.尝试用C#来写,之前没有学过C#,所以打算先花1天的时间学习C# 2. ...

  4. Individual Project - Word frequency program——12061154Joy

    Description&Requirement: http://www.cnblogs.com/jiel/p/3978727.html 项目时间估计 理解项目要求: 1h 构建项目逻辑: 1h ...

  5. SoftwareEngineering Individual Project - Word frequency program

    说实话前面c#实在没怎么学过.这次写起来感觉非常陌生,就连怎么引用名空间都忘记了.在经过恶补后还是慢慢地适应了. 1.项目预计用时: 构建并写出大概的数据结构,程序框架及模块: 30min 实现文件夹 ...

  6. Individual Project - Word frequency program

    1.项目预计用时 -计划学习C#和百度一些用法的时间:5小时 -项目本身打算写两个类,一个是遍历搜索文件夹的,另外一个用来统计单词.计划用时:5小时 2.项目实际用时 学习C#以及正则表达式的用法:3 ...

  7. Record for Individual Project ( Word frequency program )

    1.  预计时间 ● 对问题总体的理解.规划:10 min ● 设计编写程序:5 h ● 调试: 分模块-40 min; 总体-40min ● 测试(性能分析).改进:1 h 2.  实际用时 ● 对 ...

  8. THE First Individual Project - Word frequency program

    第一次写博客,这次也是本学期写到第一个程序. 老师要求网址:http://www.cnblogs.com/jiel/p/3311400.html#2777556 一.项目预计时间 一开始想使用不熟悉的 ...

  9. Project: Individual Project - Word frequency program----11061192zmx

    Description & Requirements http://www.cnblogs.com/jiel/p/3311400.html 项目时间估计 理解项目要求: 1小时 构建项目逻辑: ...

随机推荐

  1. MyISAM 和 InnoDB 讲解

    MyISAM 和 InnoDB 讲解 InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处 ...

  2. 自定义 array_map() 对应的递归函数 array_map_recursive()

    array_walk 有个原生递归函数 array_walk_recursive($arr, 'function', 'words'),但是 array_map 却没有对应的递归函数 array_ma ...

  3. 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(六)

    Service和Thread的关系 不少初学者都可能会有这样的疑惑,Service和Thread到底有什么关系呢?什么时候应该用Service,什么时候又应该用Thread? 答案是Service和T ...

  4. Windows 的 AD 域寄生于 Linux 机器

    导读 对于帐户统一管理系统或软件来说,在 Linux 下你可能知道 NIS.OpenLDAP.samba 或者是 RedHat.IBM 的产品,在 Windows 下当然就是最出名的活动目录 (AD) ...

  5. UNITY3D与iOS交互解决方案

    原地址:http://bbs.18183.com/thread-456979-1-1.html 本帖最后由 啊,将进酒 于 2014-2-27 11:17 编辑 “授人以鱼,不如授人以渔”,以UNIT ...

  6. xcode注释

    新开的项目需要先开发iOS版本,所以又把好久没写的iOS捡起来了,之前都是手动注释,最近是越来越懒了,所以在网上找了一个自动注释的插件,啊哈,其实有时候还真的挺怀念用Eclipse的时候,不过不用羡慕 ...

  7. vim中的查找和替换

    (文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 查找: Gsearch -F 'aa' -R  --include=*rb 替换: (1)在查找结果 ...

  8. Redis系列-远程连接redis并给redis加锁

    假设两台redis服务器,ip分别为:192.168.1.101和192.168.1.103,如何在101上通过redis-cli访问103上的redis呢?在远程连接103之前,先讲下redis-c ...

  9. 算法:comparable比较器的排序原理实现(二叉树中序排序)

    Comparable比较器排序远离实现 package test.java.api.api13; /** * 手工实现二叉树的比较算法: 第一遍感觉很神秘,但是真正自己写下来,就感觉很简单,理解就好: ...

  10. velocity的string转数字,numberTool

    velocity的string转数字,非常有意思: 1.通过java的包装类进行转换 #set($intString = "20") #set($Integer = 0) $Int ...