Skip to content

Commit

Permalink
README增加性能测试内容;修改版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
nianxy committed Sep 30, 2019
1 parent 836fa84 commit 14ee660
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,28 @@ String filtered = filter.filter("some text");

// filter对象可以重复使用,每次都可以通过setReplaceStr()设置不同的替换字符串
// 但它并不是线程安全的,如果请在不同线程内创建单独的filter对象
```
```

### 性能测试
简单做了一下性能测试,用例如下:
- 1000个过滤词
- 100,000个字符的文本源
- 完成不同次数的过滤

测试环境:我的2016款MacbookPro

测试结果:
```bash
# 第1次测试
Loops:10, time cost(ms):194, avg(ms):19.4
Loops:100, time cost(ms):405, avg(ms):4.05
Loops:1000, time cost(ms):3088, avg(ms):3.088
# 第2次测试
Loops:10, time cost(ms):205, avg(ms):20.5
Loops:100, time cost(ms):419, avg(ms):4.19
Loops:1000, time cost(ms):3172, avg(ms):3.172
# 第3次测试
Loops:10, time cost(ms):177, avg(ms):17.7
Loops:100, time cost(ms):418, avg(ms):4.18
Loops:1000, time cost(ms):3149, avg(ms):3.149
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.nianxy</groupId>
<artifactId>simple-sifter</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.1</version>
<packaging>jar</packaging>

<properties>
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/com/nianxy/simplesifter/WordSifterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ private String loadFile(String path) throws IOException {
return new String(content.toByteArray(), "utf8");
}

private void doFilterLoop(WordSifter.Filter filter, String doc, int count) {
long tm = System.currentTimeMillis();
for (int i=0; i<count; ++i) {
filter.filter(doc);
}
long tm2 = System.currentTimeMillis();
System.out.println("Loops:" + count + ", time cost(ms):" + (tm2-tm) + ", avg(ms):" + (tm2-tm)*1.0/count);
}

@Test
public void testCap1() throws IOException {
// 1000个关键词
Expand All @@ -111,13 +120,8 @@ public void testCap1() throws IOException {

WordSifter.Filter filter = wordSifter.createFilter();

final int LoopCount = 1000;

long tm = System.currentTimeMillis();
for (int i=0; i<LoopCount; ++i) {
filter.filter(doc);
}

System.out.println("Loop count:" + LoopCount + ", time cost(ms):" + (System.currentTimeMillis()-tm));
doFilterLoop(filter, doc, 10);
doFilterLoop(filter, doc, 100);
doFilterLoop(filter, doc, 1000);
}
}

0 comments on commit 14ee660

Please sign in to comment.