上次改脚本,直接对标题进行正则:
https://vulsee.com/archives/vulsee_2021/1202_15790.html
后来发现未先对标题是否存在关键字进行判断,怀疑对性能有影响,在本地1.3W数据测试了下:
测试:
(1)未加标题判断:
<?php
// vuless.com
//连接数据库
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "test";
// 创建连接
$conn = new mysqli($servername, $username, $password,$dbname);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功"."<br>";
//读取数据
$t1=microtime(true);
$sql = "SELECT post_title FROM wp_posts";
$result = $conn->query($sql);
echo $result->num_rows;
while($row = $result->fetch_assoc()) {
$cve = strtoupper($row["post_title"]);
$res = stristr($cve, 'cve');
preg_match_all('/(CVE|cve|CNVD|cnvd)-[0-9]{0,}-[0-9]{0,}/', $cve, $matches);
$res = $matches[0];
if (count($res)>0){
echo "--------------".$res[0]."<br>";
}
}
echo "<br/>";
$t2 = microtime(true);
echo ($t2-$t1)*1000;
?>
读取耗时约:1520ms左右
(2)加标题判断:
<?php
//连接数据库
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "test";
// 创建连接
$conn = new mysqli($servername, $username, $password,$dbname);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功"."<br>";
//读取数据
$t1=microtime(true);
$sql = "SELECT post_title FROM wp_posts";
$result = $conn->query($sql);
echo $result->num_rows;
while($row = $result->fetch_assoc()) {
$cve = strtoupper($row["post_title"]);
$res = stristr($cve, 'cve');
if($res==true){
preg_match_all('/(CVE|cve|CNVD|cnvd)-[0-9]{0,}-[0-9]{0,}/', $cve, $matches);
$res = $matches[0];
if (count($res)>0){
echo "--------------".$res[0]."<br>";
}
}
}
echo "<br/>";
$t2 = microtime(true);
echo ($t2-$t1)*1000;
// vuless.com
?>
读取耗时约:1220ms左右
结论:
在处理大量数据的时候,效果还是笔记明显的,如果是单条数据,也大约有1-2ms的区别