mirror of
https://github.com/toolgood/ToolGood.Words.git
synced 2026-10-26 02:19:30 +08:00
修改 移植代码
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package com.example.demo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import ToolGood.Words.StringSearch;
|
||||
import ToolGood.Words.StringSearchEx;
|
||||
@@ -24,7 +30,7 @@ public class DemoApplication {
|
||||
} catch (Exception e) {
|
||||
//TODO: handle exception
|
||||
}
|
||||
|
||||
test_times();
|
||||
}
|
||||
|
||||
private static void test_StringSearch(){
|
||||
@@ -230,4 +236,43 @@ public class DemoApplication {
|
||||
System.out.println("Replace is Error.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test_times(){
|
||||
String ts= readLineByLineJava8("BadWord.txt");
|
||||
String[] sp=ts.split("[\r\n]");
|
||||
List<String> list=new ArrayList<String>();
|
||||
for (String item : sp) {
|
||||
list.add(item);
|
||||
}
|
||||
String words= readLineByLineJava8("Talk.txt");
|
||||
|
||||
StringSearchEx iwords = new StringSearchEx();
|
||||
iwords.SetKeywords(list);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start("校验耗时");
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
// iwords.ContainsAny(words);
|
||||
iwords.FindAll(words);
|
||||
// System.out.println(list2.size());
|
||||
}
|
||||
sw.stop();
|
||||
System.out.println(sw.getTotalTimeMillis()+"ms");
|
||||
|
||||
}
|
||||
|
||||
private static String readLineByLineJava8(String filePath)
|
||||
{
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
try (Stream<String> stream = Files.lines(
|
||||
Paths.get(filePath), StandardCharsets.UTF_8))
|
||||
{
|
||||
stream.forEach(s -> contentBuilder.append(s).append("\n"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return contentBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user