save
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# 应用配置
|
||||
# 调试模式 (true/false)
|
||||
debug=false
|
||||
|
||||
# 地址列表 (格式: addX=ip:port)
|
||||
add1=127.0.0.1:8889
|
||||
add2=172.1.41.129:8889
|
||||
@@ -157,14 +157,25 @@ public class SydApiLongLinkWrap implements SydApi {
|
||||
|
||||
@Override
|
||||
public DataAndMac SYD_SM4_EncryptAndMac_ShortData(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData) {
|
||||
FutureTask<DataAndMac> task = builder.getLongLinkWorks().fTask(new Callable<DataAndMac>() {
|
||||
try {
|
||||
FutureTask<byte[]> taskEnc = builder.getLongLinkWorks().fTask(new Callable<byte[]>() {
|
||||
@Override
|
||||
public DataAndMac call() throws Exception {
|
||||
return builder.get().SYD_SM4_EncryptAndMac_ShortData(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||
public byte[] call() throws Exception {
|
||||
return builder.get().SYD_SM4_ShortData(iEncKeyIndex, pcData, Consts.ECB_ENC);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return task.get();
|
||||
|
||||
byte[] enData = taskEnc.get();
|
||||
|
||||
FutureTask<String> taskMac = builder.getLongLinkWorks().fTask(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return builder.get().SYD_SM4Mac_ShortData(iMacKeyIndex, enData);
|
||||
}
|
||||
});
|
||||
|
||||
String mac = taskMac.get();
|
||||
return new DataAndMac(enData, mac);
|
||||
} catch (Exception e) {
|
||||
throw new SydApiException("并行任务执行失败", 0xC101, e);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class PoolConfig {
|
||||
private int keepAliveNumber = 5;
|
||||
|
||||
// 最大连接数
|
||||
private int maxAliveNumber = 30;
|
||||
private int maxAliveNumber = 60;
|
||||
|
||||
public long getMaxIdle() {
|
||||
return maxIdle;
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Config {
|
||||
private boolean debug = false;
|
||||
private String[] ips = new String[]{"127.0.0.1", "172.1.41.129"};
|
||||
private int[] ports = new int[]{8889, 8889};
|
||||
private int maxThread = 40;
|
||||
private int total = 100000;
|
||||
|
||||
private static final String CONFIG_FILE = "config.properties";
|
||||
|
||||
// 生成默认配置字符串
|
||||
private String generateDefaultConfig() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("# 应用配置\n");
|
||||
sb.append("# 调试模式 (true/false)\n");
|
||||
sb.append("debug=").append(this.debug).append("\n\n");
|
||||
sb.append("# 最大线程数\n");
|
||||
sb.append("maxThread=").append(this.maxThread).append("\n\n");
|
||||
sb.append("# 总数\n");
|
||||
sb.append("total=").append(this.total).append("\n\n");
|
||||
sb.append("# 地址列表 (格式: addrX=ip:port)\n");
|
||||
|
||||
// 根据当前ips和ports生成默认配置
|
||||
for (int i = 0; i < Math.min(ips.length, ports.length); i++) {
|
||||
sb.append("addr").append(i+1).append("=")
|
||||
.append(ips[i]).append(":").append(ports[i]).append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Config loadConfig() {
|
||||
Config config = new Config();
|
||||
|
||||
// 如果配置文件不存在,创建默认配置
|
||||
File configFile = new File(CONFIG_FILE);
|
||||
if (!configFile.exists()) {
|
||||
try (FileWriter writer = new FileWriter(configFile)) {
|
||||
writer.write(config.generateDefaultConfig());
|
||||
System.out.println("配置文件不存在,已创建默认配置文件: " + CONFIG_FILE);
|
||||
} catch (IOException e) {
|
||||
System.err.println("创建配置文件失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 读取配置文件
|
||||
Properties props = new Properties();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(configFile))) {
|
||||
// 过滤掉注释行
|
||||
String line;
|
||||
StringBuilder filteredContent = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().startsWith("#") && !line.trim().isEmpty()) {
|
||||
filteredContent.append(line).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载过滤后的配置
|
||||
props.load(new StringReader(filteredContent.toString()));
|
||||
} catch (IOException e) {
|
||||
System.err.println("读取配置文件失败: " + e.getMessage());
|
||||
return config; // 返回默认配置
|
||||
}
|
||||
|
||||
// 解析配置
|
||||
config.setDebug(Boolean.parseBoolean(props.getProperty("debug", String.valueOf(config.debug))));
|
||||
try {
|
||||
config.setMaxThread(Integer.parseInt(props.getProperty("maxThread", String.valueOf(config.maxThread))));
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("无效的maxThread值,使用默认值: " + config.maxThread);
|
||||
}
|
||||
try {
|
||||
config.setTotal(Integer.parseInt(props.getProperty("total", String.valueOf(config.total))));
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("无效的total值,使用默认值: " + config.total);
|
||||
}
|
||||
|
||||
// 处理地址列表
|
||||
List<String> ipList = new ArrayList<>();
|
||||
List<Integer> portList = new ArrayList<>();
|
||||
|
||||
for (String key : props.stringPropertyNames()) {
|
||||
if (key.startsWith("addr")) {
|
||||
String value = props.getProperty(key);
|
||||
String[] parts = value.split(":");
|
||||
if (parts.length == 2) {
|
||||
ipList.add(parts[0]);
|
||||
try {
|
||||
portList.add(Integer.parseInt(parts[1]));
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("无效的端口号: " + parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为数组
|
||||
if (!ipList.isEmpty()) {
|
||||
config.ips = ipList.toArray(new String[0]);
|
||||
config.ports = new int[portList.size()];
|
||||
for (int i = 0; i < portList.size(); i++) {
|
||||
config.ports[i] = portList.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public String[] getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
public void setIps(String[] ips) {
|
||||
this.ips = ips;
|
||||
}
|
||||
|
||||
public int[] getPorts() {
|
||||
return ports;
|
||||
}
|
||||
|
||||
public void setPorts(int[] ports) {
|
||||
this.ports = ports;
|
||||
}
|
||||
|
||||
public int getMaxThread() {
|
||||
return maxThread;
|
||||
}
|
||||
|
||||
public void setMaxThread(int maxThread) {
|
||||
this.maxThread = maxThread;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Config{debug=").append(debug);
|
||||
sb.append(", maxThread=").append(maxThread);
|
||||
sb.append(", total=").append(total);
|
||||
sb.append(", ips=[");
|
||||
for (String ip : ips) {
|
||||
sb.append(ip).append(", ");
|
||||
}
|
||||
sb.append("], ports=[");
|
||||
for (int port : ports) {
|
||||
sb.append(port).append(", ");
|
||||
}
|
||||
sb.append("]}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Config config = Config.loadConfig();
|
||||
System.out.println("加载的配置:");
|
||||
System.out.println(config);
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@ public class LongDataTest {
|
||||
public void sm4mac_case3() {
|
||||
ISM4Mac sydApiMac = api.initSM4Mac(0);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[66];
|
||||
|
||||
+156
-107
@@ -22,37 +22,54 @@ public class TestAll {
|
||||
public static final int ECB_DEC = 0;
|
||||
public static final int ECB_ENC = 1;
|
||||
|
||||
public static void showmenu() {
|
||||
System.out.println("请选择测试项:");
|
||||
System.out.println("1.SM4短数据加解密");
|
||||
System.out.println("2.SM4批量数据加解密");
|
||||
System.out.println("3.SM4-MAC短数据");
|
||||
System.out.println("4.SM4-MAC批量数据");
|
||||
System.out.println("5.SM3短数据");
|
||||
System.out.println("6.SM4短数据加密后生成MAC,解密验证MAC");
|
||||
System.out.println("7.SM4批量数据加密后生成MAC,解密验证MAC");
|
||||
System.out.println("8.SM4长数据加解密");
|
||||
System.out.println("9.SM4长数据MAC");
|
||||
System.out.println("10.SM3长数据");
|
||||
System.out.println("11.功能全量测试");
|
||||
System.out.println("12.性能全量测试");
|
||||
System.out.println("13. 短数据 SM4+MAC性能测试");
|
||||
System.out.println("14. 批量数据 SM4+MAC性能测试");
|
||||
System.out.println("-1.退出");
|
||||
|
||||
|
||||
public static void setLog(){
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "false");
|
||||
}
|
||||
|
||||
public static void menu1(Config config, Choise choise, TestAll test) throws Exception {
|
||||
|
||||
|
||||
|
||||
while ( true ) {
|
||||
System.out.println("请选择测试项:");
|
||||
System.out.println("1. 功能单项测试");
|
||||
System.out.println("2. 功能全量测试");
|
||||
System.out.println("3. 性能单项测试");
|
||||
System.out.println("4. 性能全量测试");
|
||||
|
||||
System.out.println("-1. 退出");
|
||||
|
||||
switch (choise.getAsInt()) {
|
||||
case 1:
|
||||
test.funcAll();
|
||||
break;
|
||||
case 3:
|
||||
perfMenu(config, choise, test);
|
||||
break;
|
||||
case 4:
|
||||
test.perfAll();
|
||||
break;
|
||||
default:
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sm4ShortEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4短数据加解密性能测试开始 --------");
|
||||
sm4ShortEnde(1, 10000, 1024);
|
||||
sm4ShortEnde(40, 100000, 1024);
|
||||
sm4ShortEnde(1, config.getTotal(), 1024);
|
||||
sm4ShortEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4短数据加解密性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
public void sm4ShortEnde(int numberOfThreads, int totalRequest, int plainLen) throws InterruptedException {
|
||||
byte[] data = new byte[plainLen];
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -83,7 +100,7 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
SydApi apiTest = Api.get();
|
||||
byte[] res = apiTest.SYD_SM4_ShortData(0, data, ECB_ENC);
|
||||
@@ -106,14 +123,14 @@ public class TestAll {
|
||||
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + tps);
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4BatchEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4批量数据加解密性能测试开始 --------");
|
||||
sm4BatchEnde(1, 100000, 1024);
|
||||
sm4BatchEnde(40, 100000, 1024);
|
||||
sm4BatchEnde(1, config.getTotal(), 1024);
|
||||
sm4BatchEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4批量数据加解密性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
@@ -126,8 +143,8 @@ public class TestAll {
|
||||
data.add(new byte[1000]);
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -158,7 +175,7 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
SydApi apiTest = Api.get();
|
||||
List<byte[]> res = apiTest.SYD_SM4_BatchData(keyIdx, data, ECB_ENC);
|
||||
@@ -181,22 +198,22 @@ public class TestAll {
|
||||
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + tps);
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4macShortEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4MAC短数据性能测试开始 --------");
|
||||
sm4macShortEnde(1, 100000, 1024);
|
||||
sm4macShortEnde(40, 100000, 1024);
|
||||
sm4macShortEnde(1, config.getTotal(), 1024);
|
||||
sm4macShortEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4MAC短数据性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
public void sm4macShortEnde(int numberOfThreads, int totalRequest, int plainLen) throws InterruptedException {
|
||||
byte[] data = new byte[plainLen];
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -227,21 +244,21 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4macBatchEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4MAC批量数据性能测试开始 --------");
|
||||
sm4macBatchEnde(1, 100, 1024);
|
||||
// sm4macBatchEnde(40, 100000, 1024);
|
||||
// sm4macBatchEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4MAC批量数据性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
public void sm4macBatchEnde(int numberOfThreads, int totalRequest, int plainLen) throws InterruptedException {
|
||||
int[] keyIdx = new int[]{0, 1, 0, 1};
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -278,21 +295,21 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm3ShortEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM3短数据性能测试开始 --------");
|
||||
sm3ShortEnde(1, 100000, 1024);
|
||||
sm3ShortEnde(40, 100000, 1024);
|
||||
sm3ShortEnde(1, config.getTotal(), 1024);
|
||||
sm3ShortEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM3短数据性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
public void sm3ShortEnde(int numberOfThreads, int totalRequest, int plainLen) throws InterruptedException {
|
||||
byte[] data = new byte[plainLen];
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -323,16 +340,16 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4ShortMacEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4短数据加密生成MAC,解密验证MAC性能测试开始 --------");
|
||||
System.out.println("单线程");
|
||||
sm4ShortMacEnde(1, 10000, 1024);
|
||||
sm4ShortMacEnde(1, config.getTotal(), 1024);
|
||||
|
||||
System.out.println("40 线程");
|
||||
sm4ShortMacEnde(40, 100000, 1024);
|
||||
sm4ShortMacEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4短数据加密生成MAC,解密验证MAC性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
@@ -342,8 +359,8 @@ public class TestAll {
|
||||
int keyMac = 0;
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -378,7 +395,7 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
|
||||
|
||||
@@ -400,16 +417,16 @@ public class TestAll {
|
||||
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + tps);
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4BatchMacEndes() throws InterruptedException {
|
||||
System.out.println("-------- SM4批量数据加密生成MAC,解密验证MAC性能测试开始 --------");
|
||||
System.out.println("单线程");
|
||||
sm4BatchMacEnde(1, 10000, 1024);
|
||||
sm4BatchMacEnde(1, config.getTotal(), 1024);
|
||||
System.out.println("40 线程");
|
||||
sm4BatchMacEnde(40, 100000, 1024);
|
||||
sm4BatchMacEnde(40, config.getTotal(), 1024);
|
||||
System.out.println("-------- SM4批量数据加密生成MAC,解密验证MAC性能测试结束 --------\n");
|
||||
}
|
||||
|
||||
@@ -423,8 +440,8 @@ public class TestAll {
|
||||
data.add(new byte[plainLen]);
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -459,7 +476,7 @@ public class TestAll {
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
ExecutorService poolDec = Executors.newFixedThreadPool(numberOfThreads);
|
||||
start = System.currentTimeMillis();
|
||||
@@ -479,8 +496,8 @@ public class TestAll {
|
||||
|
||||
System.out.println("并发数: " + numberOfThreads);
|
||||
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("TPS: " + tps);
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
}
|
||||
|
||||
public void sm4LongEnde() {
|
||||
@@ -491,8 +508,8 @@ public class TestAll {
|
||||
ByteBuffer enDataBuff = ByteBuffer.allocate(100 * 1024 * 1024 + 16);
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -511,7 +528,7 @@ public class TestAll {
|
||||
double throughput = 100.0 * 1000 / duration;
|
||||
|
||||
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
@@ -527,7 +544,7 @@ public class TestAll {
|
||||
throughput = 100.0 * 1000 / duration;
|
||||
|
||||
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
System.out.println("-------- SM4长数据加解密性能测试结束 --------\\n");
|
||||
|
||||
@@ -539,8 +556,8 @@ public class TestAll {
|
||||
byte[] data = new byte[1024];
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -559,7 +576,7 @@ public class TestAll {
|
||||
double throughput = 100.0 * 1000 / duration;
|
||||
|
||||
System.out.println("共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
System.out.println("-------- SM4MAC长数据性能测试结束 --------");
|
||||
}
|
||||
@@ -570,8 +587,8 @@ public class TestAll {
|
||||
byte[] data = new byte[1024];
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -590,7 +607,7 @@ public class TestAll {
|
||||
double throughput = 100.0 * 1000 / duration;
|
||||
|
||||
System.out.println("共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||
System.out.println("吞吐量: " + throughput + " MB\n");
|
||||
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S\n");
|
||||
|
||||
System.out.println("-------- SM3长数据性能测试结束 --------");
|
||||
}
|
||||
@@ -611,8 +628,8 @@ public class TestAll {
|
||||
public void longConnectFunc() {
|
||||
System.out.println("-------- 设置长连接参数与获取长连接功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -622,7 +639,7 @@ public class TestAll {
|
||||
try {
|
||||
builder = new SydApiBuilder(
|
||||
ipListErr,
|
||||
new int[]{8889, 8889},
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -639,8 +656,8 @@ public class TestAll {
|
||||
System.out.println("-------- SM3短数据功能测试开始 --------");
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -673,8 +690,8 @@ public class TestAll {
|
||||
public void sm3LongFunc() {
|
||||
System.out.println("-------- SM3长数据功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -723,8 +740,8 @@ public class TestAll {
|
||||
public void sm4ShortFunc() {
|
||||
System.out.println("-------- SM4短数据加解密功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -769,8 +786,8 @@ public class TestAll {
|
||||
public void sm4LongFunc() {
|
||||
System.out.println("-------- SM4长数据加解密功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -854,8 +871,8 @@ public class TestAll {
|
||||
public void sm4macShortFunc() {
|
||||
System.out.println("-------- SM4MAC短数据功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -896,8 +913,8 @@ public class TestAll {
|
||||
public void sm4macLongFunc() {
|
||||
System.out.println("-------- SM4MAC长数据功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -961,8 +978,8 @@ public class TestAll {
|
||||
public void sm4BatchFunc() {
|
||||
System.out.println("-------- SM4批量数据加解密功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -1017,8 +1034,8 @@ public class TestAll {
|
||||
public void sm4macBatchFunc() {
|
||||
System.out.println("-------- SM4MAC批量数据功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -1083,8 +1100,8 @@ public class TestAll {
|
||||
public void sm4ShortMacFunc() {
|
||||
System.out.println("-------- 短数据加密计算MAC,校验MAC解密功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -1129,8 +1146,8 @@ public class TestAll {
|
||||
public void sm4BatchMacFunc() {
|
||||
System.out.println("-------- 批量数据加密计算MAC,校验MAC解密功能测试开始 --------");
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
ipList,
|
||||
new int[]{8889, 8889},
|
||||
config.getIps(),
|
||||
config.getPorts(),
|
||||
1000,
|
||||
2000
|
||||
);
|
||||
@@ -1222,11 +1239,26 @@ public class TestAll {
|
||||
this.sm3LongEnde();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "false");
|
||||
|
||||
TestAll test = new TestAll();
|
||||
Choise choise = new Choise(args);
|
||||
|
||||
public static void showmenu() {
|
||||
System.out.println("请选择测试项:");
|
||||
System.out.println("1.SM4短数据加解密");
|
||||
System.out.println("2.SM4批量数据加解密");
|
||||
System.out.println("3.SM4-MAC短数据");
|
||||
System.out.println("4.SM4-MAC批量数据");
|
||||
System.out.println("5.SM3短数据");
|
||||
System.out.println("6.SM4短数据加密后生成MAC,解密验证MAC");
|
||||
System.out.println("7.SM4批量数据加密后生成MAC,解密验证MAC");
|
||||
System.out.println("8.SM4长数据加解密");
|
||||
System.out.println("9.SM4长数据MAC");
|
||||
System.out.println("10.SM3长数据");
|
||||
System.out.println("11. 短数据 SM4+MAC性能测试");
|
||||
System.out.println("12. 批量数据 SM4+MAC性能测试");
|
||||
System.out.println("-1.退出");
|
||||
}
|
||||
public static void perfMenu(Config config, Choise choise, TestAll test) throws Exception{
|
||||
|
||||
boolean flag = true;
|
||||
|
||||
while (flag) {
|
||||
@@ -1262,23 +1294,40 @@ public class TestAll {
|
||||
case 10:
|
||||
test.sm3LongEnde();
|
||||
break;
|
||||
case 11:
|
||||
test.funcAll();
|
||||
break;
|
||||
case 12:
|
||||
test.perfAll();
|
||||
break;
|
||||
case 13: {
|
||||
case 11: {
|
||||
test.sm4ShortMacEndes();
|
||||
}
|
||||
case 14: {
|
||||
test.sm4BatchMacEndes();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 12: {
|
||||
test.sm4BatchMacEndes();
|
||||
break;
|
||||
}
|
||||
case -1:
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Config config = null;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// 载入配置文件
|
||||
config = Config.loadConfig();
|
||||
if (config == null || config.isDebug()) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
}
|
||||
|
||||
System.out.println("ips=" + Arrays.toString(config.getIps()));
|
||||
System.out.println("ports=" + Arrays.toString(config.getPorts()));
|
||||
System.out.println("debug=" + config.isDebug());
|
||||
|
||||
|
||||
TestAll test = new TestAll();
|
||||
Choise choise = new Choise(args);
|
||||
menu1(config, choise, test);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user