gpt4 book ai didi

c - 为什么主机系统上的 lua 比 linux vm 上的慢?

转载 作者:IT王子 更新时间:2023-10-29 00:15:09 27 4
gpt4 key购买 nike

比较 this Lua Script 的执行时间在 Macbook Air(Mac OS 10.9.4、i5-4250U (1.3GHz)、8GB RAM)上连接到运行 Arch Linux 的 VM (virtualbox)。

在 Arch Linux virtualbox 中编译 Lua 5.2.3

首先,我使用 clang 自己编译了 lua,以将其与 Mac OS X clang 二进制文件进行比较。

使用 tcc、gcc 和 clang

$ tcc *[^ca].c lgc.c lfunc.c lua.c -lm -o luatcc
$ gcc -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luagcc
/tmp/ccxAEYH8.o: In function `os_tmpname':
loslib.c:(.text+0x29c): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
$ clang -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luaclang
/tmp/loslib-bd4ef4.o:loslib.c:function os_tmpname: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
虚拟机中的 clang 版本
$ clang --version
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

比较文件大小

$ ls -lh |grep lua
-rwxr-xr-x 1 markus markus 210K 20. Aug 18:21 luaclang
-rwxr-xr-x 1 markus markus 251K 20. Aug 18:22 luagcc
-rwxr-xr-x 1 markus markus 287K 20. Aug 18:22 luatcc

虚拟机基准测试

clang 二进制 ~3.1 秒

$ time ./luaclang sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real 0m3.124s
user 0m3.100s
sys 0m0.020s

gcc 二进制 ~3.09 秒

$ time ./luagcc sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real 0m3.090s
user 0m3.080s
sys 0m0.007s

tcc 二进制 ~7.0 秒 - 不足为奇 :)

$ time ./luatcc sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real 0m7.071s
user 0m7.053s
sys 0m0.010s

在 Mac OS X 上编译

现在使用与 VM 中相同的 clang 命令/选项编译 lua。

$ clang -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luaclangmac
loslib.c:108:3: warning: 'tmpnam' is deprecated: This function is provided for
compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3),
it is highly recommended that you use mkstemp(3)
instead. [-Wdeprecated-declarations]
lua_tmpnam(buff, err);
^
loslib.c:57:33: note: expanded from macro 'lua_tmpnam'
#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
^
/usr/include/stdio.h:274:7: note: 'tmpnam' declared here
char *tmpnam(char *);
^
1 warning generated.
clang 版本 Mac OS X

我试过两个版本。 3.4.2 和 xcode 提供的那个。 3.4.2版本有点慢。

Markuss-MacBook-Air:bin markus$ ./clang --version
clang version 3.4.2 (tags/RELEASE_34/dot2-rc1)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Markuss-MacBook-Air:bin markus$ clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix

文件大小

$ ls -lh|grep lua
-rwxr-xr-x 1 markus staff 194K 20 Aug 18:26 luaclangmac

主机基准测试

clang 二进制 ~4.3 秒

$ time ./luaclangmac sumdata.lua data.log
Original Size: 117261680 kb
Compressed Size: 96727557 kb
real 0m4.338s
user 0m4.264s
sys 0m0.062s

为什么?

我原以为主机系统比虚拟化快一点(或大致相同的速度)。但并不是说宿主系统的可重现性较慢。

那么,有什么想法或解释吗?

更新2014.10.30

与此同时,我在我的 MBA 类(class)中自然安装了 Arch Linux。基准测试与 Arch Linux VM 一样快。

最佳答案

您能否尝试运行“perf stat”而不是“time”。它为您提供了更多的细节,时间测量也更准确,避免了 VM 内部的时间差异。

这是一个例子:

$ perf stat ls > /dev/null

“ls”的性能计数器统计信息:

     23.348076      task-clock (msec)         #    0.989 CPUs utilized          
2 context-switches # 0.086 K/sec
0 cpu-migrations # 0.000 K/sec
93 page-faults # 0.004 M/sec
74,628,308 cycles # 3.196 GHz [65.75%]
740,755 stalled-cycles-frontend # 0.99% frontend cycles idle [48.66%]
29,200,738 stalled-cycles-backend # 39.13% backend cycles idle [60.02%]
80,592,001 instructions # 1.08 insns per cycle
# 0.36 stalled cycles per insn
17,746,633 branches # 760.090 M/sec [60.00%]
642,360 branch-misses # 3.62% of all branches [48.64%]

0.023609439 seconds time elapsed

关于c - 为什么主机系统上的 lua 比 linux vm 上的慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25410844/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com