按照 java 算
((1000000053) + (32100000 ))/1024/1024 约等于146 兆 1000000053 1kw * 5 字节 * 3字节 32100000 32字节 * 10w
JVM 中默认的大对象大小通常是 >= 64KB。 fullSizeOf()
60w 数据,中英文混合

package cn.hutool.dfa;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Test;
import org.python.sizeof.RamUsageEstimator;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
import java.util.Arrays;
/**
* @Author: chengyangwang
* @DateTime: 2024/1/21 16:00
**/
public class DfaAyTest {
// 构建查询树
WordTree tree = new WordTree();
@Test
public void matchAllTest() {
// 开始时间
long start = System.currentTimeMillis();
System.out.println("开始时间:" + start);
// 读取当前目录下.word.txt,然后分割字符串,然后添加到查询树中
String filePath = "/Users/wcy/develop/AiyongCode/shopDepart/hutool/hutool-dfa/src/test/java/cn/hutool/dfa/word.txt"; // 替换为你的文本文件路径
try {
String content = new String(Files.readAllBytes(Paths.get(filePath)));
// 读取时间
long read = System.currentTimeMillis();
System.out.println("读取时间:" + read);
// 读取耗时
long readTime = read - start;
System.out.println("读取耗时:" + readTime);
String[] array = content.split(",");
tree.addWords(array);
// 加载时间
long load = System.currentTimeMillis();
System.out.println("加载时间:" + load);
long loadTime = load - read;
System.out.println("加载耗时:" + loadTime);
System.out.println(tree.matchAllWords("龙鹃"));
// 计算时间 计算耗时
long end = System.currentTimeMillis();
System.out.println("计算耗时:" + (end - load));
System.out.println("结束时间:" + end);
// 打印 tree 占用 内存
System.out.println("tree 数量:" + tree.size());
String size = RamUsageEstimator.humanSizeOf(tree);
System.out.println("tree 占用内存:" + size);
} catch (IOException e) {
e.printStackTrace();
}
// sleep 60秒
ThreadUtil.sleep(600000);
}
}
开始时间:1705825574941
读取时间:1705825574969
读取耗时:28
加载时间:1705825575593
加载耗时:624
[龙鹃]