-
Notifications
You must be signed in to change notification settings - Fork 496
/
BenchmarkTimesTest.java
78 lines (69 loc) · 2.56 KB
/
BenchmarkTimesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.github.houbb.sensitive.word.benchmark;
import com.github.houbb.heaven.util.util.RandomUtil;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.core.SensitiveWordHelper;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class BenchmarkTimesTest {
/**
* 测试基准:100+字符串 * 10W次
*
* V0.6.0: 1470ms,接近 7.2W QPS
* V0.7.0: 1380ms
*/
@Test
public void onlyWordAndNoReplaceTest() {
// 1W 次
SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
.enableWordCheck(true)
.enableNumCheck(false)
.enableUrlCheck(false)
.enableEmailCheck(false)
.ignoreRepeat(false)
.ignoreCase(false)
.ignoreNumStyle(false)
.ignoreChineseStyle(false)
.ignoreEnglishStyle(false)
.ignoreWidth(false)
.init();
String randomText = "你他妈的不要说脏话"+ RandomUtil.randomString("1234567890bcdefghiJKLMNOPQRSTUVWXYZ", 100)
+ "我们他妈的从来不说脏说";
long start = System.currentTimeMillis();
for(int i = 0; i < 100_000; i++) {
sensitiveWordBs.findAll(randomText);
}
long end = System.currentTimeMillis();
System.out.println("------------------ COST: " + (end-start));
}
/**
* 测试基准:100+字符串 * 10W次
*
* V0.6.0: 2744ms, 约 3.7W QPS
* V0.7.0: 2723ms
*/
@Test
public void onlyWordAndWithReplaceTest() {
// 1W 次
SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
.enableWordCheck(true)
.enableNumCheck(false)
.enableUrlCheck(false)
.enableEmailCheck(false)
.ignoreRepeat(true)
.ignoreCase(true)
.ignoreNumStyle(true)
.ignoreChineseStyle(true)
.ignoreEnglishStyle(true)
.ignoreWidth(true)
.init();
String randomText = "你他妈的不要说脏话"+ RandomUtil.randomString("1234567890bcdefghiJKLMNOPQRSTUVWXYZ", 100)
+ "我们他妈的从来不说脏说";
long start = System.currentTimeMillis();
for(int i = 0; i < 100_000; i++) {
sensitiveWordBs.findAll(randomText);
}
long end = System.currentTimeMillis();
System.out.println("------------------ COST: " + (end-start));
}
}