VMware® Workstation 15 Pro虚拟机
操作系统 Ubuntu 20.04
CPU 8核 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
内存 8G
unsigned char msg[1024];
int rc;
struct timespec ts_start, ts_end;
rc = clock_gettime(CLOCK_MONOTONIC, &ts_start);
int i=0;
for(i=0;i<5000;i++)
{
ret = ioctl(fd, IOCWREG, &msg);
if (ret) {
perror("ioctl write:");
exit(-4);
}
}
rc = clock_gettime(CLOCK_MONOTONIC, &ts_end);
printf("CLOCK_MONOTONIC reports %ld.%09ld seconds\n",ts_end.tv_sec - ts_start.tv_sec, ts_end.tv_nsec - ts_start.tv_nsec);
unsigned char msg[1024];
int rc;
struct timespec ts_start, ts_end;
rc = clock_gettime(CLOCK_MONOTONIC, &ts_start);
int i=0;
for(i=0;i<5000;i++)
{
ret = sendto(skfd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl));
if(!ret)
{
perror("sendto error\n");
close(skfd);
exit(-1);
}
//printf("send kernel:%s\n", umsg);
}
rc = clock_gettime(CLOCK_MONOTONIC, &ts_end);
printf("CLOCK_MONOTONIC reports %ld.%09ld seconds\n",ts_end.tv_sec - ts_start.tv_sec, ts_end.tv_nsec - ts_start.tv_nsec);
while true;
do echo 3 > /proc/sys/vm/drop_caches;
time ./ioctltest;
sleep 1;
done
netlink测试脚本
while true;
do echo 3 > /proc/sys/vm/drop_caches;
time ./usersocket;
sleep 1;
done
CLOCK_MONOTONIC reports 0.006016295 seconds
real 0m0.015s
user 0m0.005s
sys 0m0.006s
CLOCK_MONOTONIC reports 0.006374883 seconds
real 0m0.016s
user 0m0.003s
sys 0m0.007s
CLOCK_MONOTONIC reports 0.007895143 seconds
real 0m0.018s
user 0m0.000s
sys 0m0.012s
CLOCK_MONOTONIC reports 0.006377391 seconds
real 0m0.015s
user 0m0.000s
sys 0m0.012s
CLOCK_MONOTONIC reports 0.006373939 seconds
real 0m0.015s
user 0m0.000s
sys 0m0.009s
netlink 测试数据
CLOCK_MONOTONIC reports 0.004700564 seconds
real 0m0.015s
user 0m0.003s
sys 0m0.006s
CLOCK_MONOTONIC reports 0.004535751 seconds
real 0m0.013s
user 0m0.000s
sys 0m0.008s
CLOCK_MONOTONIC reports 0.004554671 seconds
real 0m0.012s
user 0m0.000s
sys 0m0.008s
CLOCK_MONOTONIC reports 0.004469324 seconds
real 0m0.011s
user 0m0.000s
sys 0m0.007s
CLOCK_MONOTONIC reports 0.005344049 seconds
real 0m0.014s
user 0m0.000s
sys 0m0.009s
对比项 | 每次调用耗时 |
ioctl | 0.0012749766毫秒 |
netlink | 0.0009401128毫秒 |
微信扫一扫
关注该公众号